2 * RichEdit - functions dealing with editor object
4 * Copyright 2004 by Krzysztof Foltman
5 * Copyright 2005 by Cihan Altinay
6 * Copyright 2005 by Phil Krylov
7 * Copyright 2008 Eric Pouech
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 API implementation status:
27 Messages (ANSI versions not done yet)
28 + EM_AUTOURLDETECT 2.0
39 + EM_FINDTEXT (only FR_DOWN flag implemented)
40 + EM_FINDTEXTEX (only FR_DOWN flag implemented)
44 + EM_GETAUTOURLDETECT 2.0
45 - EM_GETBIDIOPTIONS 3.0
46 - EM_GETCHARFORMAT (partly done)
49 + EM_GETFIRSTVISIBLELINE (can be optimized if needed)
50 - EM_GETIMECOLOR 1.0asian
51 - EM_GETIMECOMPMODE 2.0
52 - EM_GETIMEOPTIONS 1.0asian
54 - EM_GETLANGOPTIONS 2.0
57 + EM_GETLINECOUNT returns number of rows, not of paragraphs
62 + EM_GETPASSWORDCHAR 2.0
63 - EM_GETPUNCTUATION 1.0asian
67 + EM_GETSELTEXT (ANSI&Unicode)
68 + EM_GETSCROLLPOS 3.0 (only Y value valid)
71 + EM_GETTEXTLENGTHEX (GTL_PRECISE unimplemented)
73 ? + EM_GETTEXTRANGE (ANSI&Unicode)
74 - EM_GETTYPOGRAPHYOPTIONS 3.0
77 - EM_GETWORDBREAKPROCEX
78 - EM_GETWORDWRAPMODE 1.0asian
81 + EM_LIMITTEXT (Also called EM_SETLIMITTEXT)
90 + EM_REPLACESEL (proper style?) ANSI&Unicode
94 - EM_SETBIDIOPTIONS 3.0
96 + EM_SETCHARFORMAT (partly done, no ANSI)
98 + EM_SETEVENTMASK (few notifications supported)
100 - EM_SETIMECOLOR 1.0asian
101 - EM_SETIMEOPTIONS 1.0asian
102 - EM_SETLANGOPTIONS 2.0
104 + EM_SETMODIFY (not sure if implementation is correct)
106 + EM_SETOPTIONS (partially implemented)
109 + EM_SETPASSWORDCHAR 2.0
110 - EM_SETPUNCTUATION 1.0asian
111 + EM_SETREADONLY no beep on modification attempt
113 + EM_SETRECTNP (EM_SETRECT without repainting)
115 + EM_SETSCROLLPOS 3.0
117 - EM_SETTARGETDEVICE (partial)
118 + EM_SETTEXTEX 3.0 (proper style?)
120 - EM_SETTYPOGRAPHYOPTIONS 3.0
121 + EM_SETUNDOLIMIT 2.0
122 + EM_SETWORDBREAKPROC (used only for word movement at the moment)
123 - EM_SETWORDBREAKPROCEX
124 - EM_SETWORDWRAPMODE 1.0asian
126 + EM_SHOWSCROLLBAR 2.0
127 + EM_STOPGROUPTYPING 2.0
135 + WM_GETDLGCODE (the current implementation is incomplete)
136 + WM_GETTEXT (ANSI&Unicode)
137 + WM_GETTEXTLENGTH (ANSI version sucks)
140 + WM_SETTEXT (resets undo stack !) (proper style?) ANSI&Unicode
142 - WM_STYLECHANGED (things like read-only flag)
147 * EN_CHANGE (sent from the wrong place)
164 * EN_UPDATE (sent from the wrong place)
172 + ES_DISABLENOSCROLL (scrollbar is always visible)
173 - ES_EX_NOCALLOLEINIT
175 - ES_MULTILINE (currently single line controls aren't supported)
177 - ES_READONLY (I'm not sure if beeping is the proper behaviour)
183 - ES_WANTRETURN (don't know how to do WM_GETDLGCODE part)
190 * RICHED20 TODO (incomplete):
192 * - messages/styles/notifications listed above
193 * - add remaining CHARFORMAT/PARAFORMAT fields
194 * - right/center align should strip spaces from the beginning
195 * - pictures/OLE objects (not just smiling faces that lack API support ;-) )
196 * - COM interface (looks like a major pain in the TODO list)
197 * - calculate heights of pictures (half-done)
198 * - horizontal scrolling (not even started)
199 * - hysteresis during wrapping (related to scrollbars appearing/disappearing)
201 * - how to implement EM_FORMATRANGE and EM_DISPLAYBAND ? (Mission Impossible)
202 * - italic caret with italic fonts
204 * - most notifications aren't sent at all (the most important ones are)
205 * - when should EN_SELCHANGE be sent after text change ? (before/after EN_UPDATE?)
206 * - WM_SETTEXT may use wrong style (but I'm 80% sure it's OK)
207 * - EM_GETCHARFORMAT with SCF_SELECTION may not behave 100% like in original (but very close)
208 * - full justification
211 * - ListBox & ComboBox not implemented
213 * Bugs that are probably fixed, but not so easy to verify:
214 * - EN_UPDATE/EN_CHANGE are handled very incorrectly (should be OK now)
215 * - undo for ME_JoinParagraphs doesn't store paragraph format ? (it does)
216 * - check/fix artificial EOL logic (bCursorAtEnd, hardly logical)
217 * - caret shouldn't be displayed when selection isn't empty
218 * - check refcounting in style management functions (looks perfect now, but no bugs is suspicious)
219 * - undo for setting default format (done, might be buggy)
220 * - styles might be not released properly (looks like they work like charm, but who knows?
227 #define NO_SHLWAPI_STREAM
233 #define STACK_SIZE_DEFAULT 100
234 #define STACK_SIZE_MAX 1000
236 #define TEXT_LIMIT_DEFAULT 32767
238 WINE_DEFAULT_DEBUG_CHANNEL(richedit
);
240 static BOOL
ME_RegisterEditorClass(HINSTANCE
);
242 static const WCHAR RichEdit20W
[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '2', '0', 'W', 0};
243 static const WCHAR RichEdit50W
[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '5', '0', 'W', 0};
244 static const WCHAR REListBox20W
[] = {'R','E','L','i','s','t','B','o','x','2','0','W', 0};
245 static const WCHAR REComboBox20W
[] = {'R','E','C','o','m','b','o','B','o','x','2','0','W', 0};
246 static HCURSOR hLeft
;
249 HANDLE me_heap
= NULL
;
251 static BOOL ME_ListBoxRegistered
= FALSE
;
252 static BOOL ME_ComboBoxRegistered
= FALSE
;
254 static inline int is_version_nt(void)
256 return !(GetVersion() & 0x80000000);
259 static ME_TextBuffer
*ME_MakeText(void) {
261 ME_TextBuffer
*buf
= ALLOC_OBJ(ME_TextBuffer
);
263 ME_DisplayItem
*p1
= ME_MakeDI(diTextStart
);
264 ME_DisplayItem
*p2
= ME_MakeDI(diTextEnd
);
270 p1
->member
.para
.next_para
= p2
;
271 p2
->member
.para
.prev_para
= p1
;
272 p2
->member
.para
.nCharOfs
= 0;
276 buf
->pCharStyle
= NULL
;
282 static LRESULT
ME_StreamInText(ME_TextEditor
*editor
, DWORD dwFormat
, ME_InStream
*stream
, ME_Style
*style
)
284 WCHAR wszText
[STREAMIN_BUFFER_SIZE
+1];
287 TRACE("%08x %p\n", dwFormat
, stream
);
294 ME_StreamInFill(stream
);
295 if (stream
->editstream
->dwError
)
301 if (!(dwFormat
& SF_UNICODE
))
303 /* FIXME? this is doomed to fail on true MBCS like UTF-8, luckily they're unlikely to be used as CP_ACP */
304 nWideChars
= MultiByteToWideChar(CP_ACP
, 0, stream
->buffer
, stream
->dwSize
, wszText
, STREAMIN_BUFFER_SIZE
);
309 nWideChars
= stream
->dwSize
>> 1;
310 pText
= (WCHAR
*)stream
->buffer
;
313 ME_InsertTextFromCursor(editor
, 0, pText
, nWideChars
, style
);
314 if (stream
->dwSize
== 0)
318 ME_CommitUndo(editor
);
319 ME_UpdateRepaint(editor
);
323 static void ME_ApplyBorderProperties(RTF_Info
*info
,
324 ME_BorderRect
*borderRect
,
325 RTFBorder
*borderDef
)
328 ME_Border
*pBorders
[] = {&borderRect
->top
,
332 for (i
= 0; i
< 4; i
++)
334 RTFColor
*colorDef
= info
->colorList
;
335 pBorders
[i
]->width
= borderDef
[i
].width
;
336 colorNum
= borderDef
[i
].color
;
337 while (colorDef
&& colorDef
->rtfCNum
!= colorNum
)
338 colorDef
= colorDef
->rtfNextColor
;
340 pBorders
[i
]->colorRef
= RGB(
341 colorDef
->rtfCRed
>= 0 ? colorDef
->rtfCRed
: 0,
342 colorDef
->rtfCGreen
>= 0 ? colorDef
->rtfCGreen
: 0,
343 colorDef
->rtfCBlue
>= 0 ? colorDef
->rtfCBlue
: 0);
345 pBorders
[i
]->colorRef
= RGB(0, 0, 0);
349 void ME_RTFCharAttrHook(RTF_Info
*info
)
352 fmt
.cbSize
= sizeof(fmt
);
356 switch(info
->rtfMinor
)
359 /* FIXME add more flags once they're implemented */
360 fmt
.dwMask
= CFM_BOLD
| CFM_ITALIC
| CFM_UNDERLINETYPE
| CFM_STRIKEOUT
| CFM_COLOR
| CFM_BACKCOLOR
| CFM_SIZE
| CFM_WEIGHT
;
361 fmt
.dwEffects
= CFE_AUTOCOLOR
| CFE_AUTOBACKCOLOR
;
362 fmt
.yHeight
= 12*20; /* 12pt */
363 fmt
.wWeight
= FW_NORMAL
;
364 fmt
.bUnderlineType
= CFU_UNDERLINENONE
;
367 fmt
.dwMask
= CFM_BOLD
| CFM_WEIGHT
;
368 fmt
.dwEffects
= info
->rtfParam
? CFE_BOLD
: 0;
369 fmt
.wWeight
= info
->rtfParam
? FW_BOLD
: FW_NORMAL
;
372 fmt
.dwMask
= CFM_ITALIC
;
373 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
376 fmt
.dwMask
= CFM_UNDERLINETYPE
;
377 fmt
.bUnderlineType
= info
->rtfParam
? CFU_CF1UNDERLINE
: CFU_UNDERLINENONE
;
379 case rtfDotUnderline
:
380 fmt
.dwMask
= CFM_UNDERLINETYPE
;
381 fmt
.bUnderlineType
= info
->rtfParam
? CFU_UNDERLINEDOTTED
: CFU_UNDERLINENONE
;
384 fmt
.dwMask
= CFM_UNDERLINETYPE
;
385 fmt
.bUnderlineType
= info
->rtfParam
? CFU_UNDERLINEDOUBLE
: CFU_UNDERLINENONE
;
387 case rtfWordUnderline
:
388 fmt
.dwMask
= CFM_UNDERLINETYPE
;
389 fmt
.bUnderlineType
= info
->rtfParam
? CFU_UNDERLINEWORD
: CFU_UNDERLINENONE
;
392 fmt
.dwMask
= CFM_UNDERLINETYPE
;
393 fmt
.bUnderlineType
= CFU_UNDERLINENONE
;
396 fmt
.dwMask
= CFM_STRIKEOUT
;
397 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
401 case rtfSubScrShrink
:
402 case rtfSuperScrShrink
:
404 fmt
.dwMask
= CFM_SUBSCRIPT
|CFM_SUPERSCRIPT
;
405 if (info
->rtfMinor
== rtfSubScrShrink
) fmt
.dwEffects
= CFE_SUBSCRIPT
;
406 if (info
->rtfMinor
== rtfSuperScrShrink
) fmt
.dwEffects
= CFE_SUPERSCRIPT
;
407 if (info
->rtfMinor
== rtfNoSuperSub
) fmt
.dwEffects
= 0;
410 fmt
.dwMask
= CFM_HIDDEN
;
411 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
414 fmt
.dwMask
= CFM_BACKCOLOR
;
416 if (info
->rtfParam
== 0)
417 fmt
.dwEffects
= CFE_AUTOBACKCOLOR
;
418 else if (info
->rtfParam
!= rtfNoParam
)
420 RTFColor
*c
= RTFGetColor(info
, info
->rtfParam
);
421 fmt
.crTextColor
= (c
->rtfCBlue
<<16)|(c
->rtfCGreen
<<8)|(c
->rtfCRed
);
425 fmt
.dwMask
= CFM_COLOR
;
427 if (info
->rtfParam
== 0)
428 fmt
.dwEffects
= CFE_AUTOCOLOR
;
429 else if (info
->rtfParam
!= rtfNoParam
)
431 RTFColor
*c
= RTFGetColor(info
, info
->rtfParam
);
433 fmt
.crTextColor
= (c
->rtfCBlue
<<16)|(c
->rtfCGreen
<<8)|(c
->rtfCRed
);
439 if (info
->rtfParam
!= rtfNoParam
)
441 RTFFont
*f
= RTFGetFont(info
, info
->rtfParam
);
444 MultiByteToWideChar(CP_ACP
, 0, f
->rtfFName
, -1, fmt
.szFaceName
, sizeof(fmt
.szFaceName
)/sizeof(WCHAR
));
445 fmt
.szFaceName
[sizeof(fmt
.szFaceName
)/sizeof(WCHAR
)-1] = '\0';
446 fmt
.bCharSet
= f
->rtfFCharSet
;
447 fmt
.dwMask
= CFM_FACE
| CFM_CHARSET
;
448 fmt
.bPitchAndFamily
= f
->rtfFPitch
| (f
->rtfFFamily
<< 4);
453 fmt
.dwMask
= CFM_SIZE
;
454 if (info
->rtfParam
!= rtfNoParam
)
455 fmt
.yHeight
= info
->rtfParam
*10;
460 RTFFlushOutputBuffer(info
);
461 /* FIXME too slow ? how come ? */
462 style2
= ME_ApplyStyle(info
->style
, &fmt
);
463 ME_ReleaseStyle(info
->style
);
464 info
->style
= style2
;
465 info
->styleChanged
= TRUE
;
469 /* FIXME this function doesn't get any information about context of the RTF tag, which is very bad,
470 the same tags mean different things in different contexts */
471 void ME_RTFParAttrHook(RTF_Info
*info
)
474 fmt
.cbSize
= sizeof(fmt
);
477 switch(info
->rtfMinor
)
479 case rtfParDef
: /* restores default paragraph attributes */
480 if (!info
->editor
->bEmulateVersion10
) /* v4.1 */
481 info
->borderType
= RTFBorderParaLeft
;
482 else /* v1.0 - 3.0 */
483 info
->borderType
= RTFBorderParaTop
;
484 fmt
.dwMask
= PFM_ALIGNMENT
| PFM_BORDER
| PFM_LINESPACING
| PFM_TABSTOPS
|
485 PFM_OFFSET
| PFM_RIGHTINDENT
| PFM_SPACEAFTER
| PFM_SPACEBEFORE
|
487 /* TODO: numbering, shading */
488 fmt
.wAlignment
= PFA_LEFT
;
490 fmt
.dxOffset
= fmt
.dxStartIndent
= fmt
.dxRightIndent
= 0;
491 fmt
.wBorderWidth
= fmt
.wBorders
= 0;
492 fmt
.wBorderSpace
= 0;
493 fmt
.bLineSpacingRule
= 0;
494 fmt
.dySpaceBefore
= fmt
.dySpaceAfter
= 0;
495 fmt
.dyLineSpacing
= 0;
496 if (!info
->editor
->bEmulateVersion10
) /* v4.1 */
498 if (info
->tableDef
&& info
->tableDef
->tableRowStart
&&
499 info
->tableDef
->tableRowStart
->member
.para
.nFlags
& MEPF_ROWEND
)
502 ME_DisplayItem
*para
;
503 /* We are just after a table row. */
504 RTFFlushOutputBuffer(info
);
505 cursor
= info
->editor
->pCursors
[0];
506 para
= ME_GetParagraph(cursor
.pRun
);
507 if (para
== info
->tableDef
->tableRowStart
->member
.para
.next_para
508 && !cursor
.nOffset
&& !cursor
.pRun
->member
.run
.nCharOfs
)
510 /* Since the table row end, no text has been inserted, and the \intbl
511 * control word has not be used. We can confirm that we are not in a
514 info
->tableDef
->tableRowStart
= NULL
;
515 info
->canInheritInTbl
= FALSE
;
518 } else { /* v1.0 - v3.0 */
519 fmt
.dwMask
|= PFM_TABLE
;
520 fmt
.wEffects
&= ~PFE_TABLE
;
524 if (!info
->editor
->bEmulateVersion10
) /* v4.1 */
526 while (info
->rtfParam
> info
->nestingLevel
) {
527 RTFTable
*tableDef
= ALLOC_OBJ(RTFTable
);
528 ZeroMemory(tableDef
, sizeof(RTFTable
));
529 tableDef
->parent
= info
->tableDef
;
530 info
->tableDef
= tableDef
;
532 RTFFlushOutputBuffer(info
);
533 if (tableDef
->tableRowStart
&&
534 tableDef
->tableRowStart
->member
.para
.nFlags
& MEPF_ROWEND
)
536 ME_DisplayItem
*para
= tableDef
->tableRowStart
;
537 para
= para
->member
.para
.next_para
;
538 para
= ME_InsertTableRowStartAtParagraph(info
->editor
, para
);
539 tableDef
->tableRowStart
= para
;
543 cursor
= info
->editor
->pCursors
[0];
544 if (cursor
.nOffset
|| cursor
.pRun
->member
.run
.nCharOfs
)
545 ME_InsertTextFromCursor(info
->editor
, 0, &endl
, 1, info
->style
);
546 tableDef
->tableRowStart
= ME_InsertTableRowStartFromCursor(info
->editor
);
549 info
->nestingLevel
++;
551 info
->canInheritInTbl
= FALSE
;
556 if (!info
->editor
->bEmulateVersion10
) /* v4.1 */
558 if (info
->nestingLevel
< 1)
563 info
->tableDef
= ALLOC_OBJ(RTFTable
);
564 ZeroMemory(info
->tableDef
, sizeof(RTFTable
));
566 tableDef
= info
->tableDef
;
567 RTFFlushOutputBuffer(info
);
568 if (tableDef
->tableRowStart
&&
569 tableDef
->tableRowStart
->member
.para
.nFlags
& MEPF_ROWEND
)
571 ME_DisplayItem
*para
= tableDef
->tableRowStart
;
572 para
= para
->member
.para
.next_para
;
573 para
= ME_InsertTableRowStartAtParagraph(info
->editor
, para
);
574 tableDef
->tableRowStart
= para
;
578 cursor
= info
->editor
->pCursors
[0];
579 if (cursor
.nOffset
|| cursor
.pRun
->member
.run
.nCharOfs
)
580 ME_InsertTextFromCursor(info
->editor
, 0, &endl
, 1, info
->style
);
581 tableDef
->tableRowStart
= ME_InsertTableRowStartFromCursor(info
->editor
);
583 info
->nestingLevel
= 1;
584 info
->canInheritInTbl
= TRUE
;
587 } else { /* v1.0 - v3.0 */
588 fmt
.dwMask
|= PFM_TABLE
;
589 fmt
.wEffects
|= PFE_TABLE
;
594 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
595 fmt
.dwMask
= PFM_STARTINDENT
| PFM_OFFSET
;
596 fmt
.dxStartIndent
+= fmt
.dxOffset
+ info
->rtfParam
;
597 fmt
.dxOffset
= -info
->rtfParam
;
600 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
601 fmt
.dwMask
= PFM_STARTINDENT
;
602 fmt
.dxStartIndent
= info
->rtfParam
- fmt
.dxOffset
;
605 fmt
.dwMask
= PFM_RIGHTINDENT
;
606 fmt
.dxRightIndent
= info
->rtfParam
;
610 fmt
.dwMask
= PFM_ALIGNMENT
;
611 fmt
.wAlignment
= PFA_LEFT
;
614 fmt
.dwMask
= PFM_ALIGNMENT
;
615 fmt
.wAlignment
= PFA_RIGHT
;
618 fmt
.dwMask
= PFM_ALIGNMENT
;
619 fmt
.wAlignment
= PFA_CENTER
;
622 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
623 if (!(fmt
.dwMask
& PFM_TABSTOPS
))
627 if (fmt
.cTabCount
< MAX_TAB_STOPS
&& info
->rtfParam
< 0x1000000)
628 fmt
.rgxTabs
[fmt
.cTabCount
++] = info
->rtfParam
;
629 fmt
.dwMask
= PFM_TABSTOPS
;
632 fmt
.dwMask
= PFM_KEEP
;
633 fmt
.wEffects
= PFE_KEEP
;
635 case rtfNoWidowControl
:
636 fmt
.dwMask
= PFM_NOWIDOWCONTROL
;
637 fmt
.wEffects
= PFE_NOWIDOWCONTROL
;
640 fmt
.dwMask
= PFM_KEEPNEXT
;
641 fmt
.wEffects
= PFE_KEEPNEXT
;
644 fmt
.dwMask
= PFM_SPACEAFTER
;
645 fmt
.dySpaceAfter
= info
->rtfParam
;
648 fmt
.dwMask
= PFM_SPACEBEFORE
;
649 fmt
.dySpaceBefore
= info
->rtfParam
;
651 case rtfSpaceBetween
:
652 fmt
.dwMask
= PFM_LINESPACING
;
653 if ((int)info
->rtfParam
> 0)
655 fmt
.dyLineSpacing
= info
->rtfParam
;
656 fmt
.bLineSpacingRule
= 3;
660 fmt
.dyLineSpacing
= info
->rtfParam
;
661 fmt
.bLineSpacingRule
= 4;
663 case rtfSpaceMultiply
:
664 fmt
.dwMask
= PFM_LINESPACING
;
665 fmt
.dyLineSpacing
= info
->rtfParam
* 20;
666 fmt
.bLineSpacingRule
= 5;
669 fmt
.dwMask
= PFM_NUMBERING
;
670 fmt
.wNumbering
= PFN_BULLET
;
673 fmt
.dwMask
= PFM_NUMBERING
;
674 fmt
.wNumbering
= 2; /* FIXME: MSDN says it's not used ?? */
676 case rtfParNumDecimal
:
677 fmt
.dwMask
= PFM_NUMBERING
;
678 fmt
.wNumbering
= 2; /* FIXME: MSDN says it's not used ?? */
680 case rtfParNumIndent
:
681 fmt
.dwMask
= PFM_NUMBERINGTAB
;
682 fmt
.wNumberingTab
= info
->rtfParam
;
684 case rtfParNumStartAt
:
685 fmt
.dwMask
= PFM_NUMBERINGSTART
;
686 fmt
.wNumberingStart
= info
->rtfParam
;
689 info
->borderType
= RTFBorderParaLeft
;
690 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
691 if (!(fmt
.dwMask
& PFM_BORDER
))
693 fmt
.wBorderSpace
= 0;
694 fmt
.wBorderWidth
= 1;
698 fmt
.dwMask
= PFM_BORDER
;
701 info
->borderType
= RTFBorderParaRight
;
702 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
703 if (!(fmt
.dwMask
& PFM_BORDER
))
705 fmt
.wBorderSpace
= 0;
706 fmt
.wBorderWidth
= 1;
710 fmt
.dwMask
= PFM_BORDER
;
713 info
->borderType
= RTFBorderParaTop
;
714 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
715 if (!(fmt
.dwMask
& PFM_BORDER
))
717 fmt
.wBorderSpace
= 0;
718 fmt
.wBorderWidth
= 1;
722 fmt
.dwMask
= PFM_BORDER
;
724 case rtfBorderBottom
:
725 info
->borderType
= RTFBorderParaBottom
;
726 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
727 if (!(fmt
.dwMask
& PFM_BORDER
))
729 fmt
.wBorderSpace
= 0;
730 fmt
.wBorderWidth
= 1;
734 fmt
.dwMask
= PFM_BORDER
;
736 case rtfBorderSingle
:
737 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
738 /* we assume that borders have been created before (RTF spec) */
739 fmt
.wBorders
&= ~0x700;
740 fmt
.wBorders
|= 1 << 8;
741 fmt
.dwMask
= PFM_BORDER
;
744 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
745 /* we assume that borders have been created before (RTF spec) */
746 fmt
.wBorders
&= ~0x700;
747 fmt
.wBorders
|= 2 << 8;
748 fmt
.dwMask
= PFM_BORDER
;
750 case rtfBorderShadow
:
751 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
752 /* we assume that borders have been created before (RTF spec) */
753 fmt
.wBorders
&= ~0x700;
754 fmt
.wBorders
|= 10 << 8;
755 fmt
.dwMask
= PFM_BORDER
;
757 case rtfBorderDouble
:
758 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
759 /* we assume that borders have been created before (RTF spec) */
760 fmt
.wBorders
&= ~0x700;
761 fmt
.wBorders
|= 7 << 8;
762 fmt
.dwMask
= PFM_BORDER
;
765 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
766 /* we assume that borders have been created before (RTF spec) */
767 fmt
.wBorders
&= ~0x700;
768 fmt
.wBorders
|= 11 << 8;
769 fmt
.dwMask
= PFM_BORDER
;
773 int borderSide
= info
->borderType
& RTFBorderSideMask
;
774 RTFTable
*tableDef
= info
->tableDef
;
775 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
776 /* we assume that borders have been created before (RTF spec) */
777 fmt
.wBorderWidth
|= ((info
->rtfParam
/ 15) & 7) << 8;
778 if ((info
->borderType
& RTFBorderTypeMask
) == RTFBorderTypeCell
)
781 if (!tableDef
|| tableDef
->numCellsDefined
>= MAX_TABLE_CELLS
)
783 border
= &tableDef
->cells
[tableDef
->numCellsDefined
].border
[borderSide
];
784 border
->width
= info
->rtfParam
;
787 fmt
.dwMask
= PFM_BORDER
;
791 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
792 /* we assume that borders have been created before (RTF spec) */
793 fmt
.wBorderSpace
= info
->rtfParam
;
794 fmt
.dwMask
= PFM_BORDER
;
798 RTFTable
*tableDef
= info
->tableDef
;
799 int borderSide
= info
->borderType
& RTFBorderSideMask
;
800 int borderType
= info
->borderType
& RTFBorderTypeMask
;
803 case RTFBorderTypePara
:
804 if (!info
->editor
->bEmulateVersion10
) /* v4.1 */
806 /* v1.0 - 3.0 treat paragraph and row borders the same. */
807 case RTFBorderTypeRow
:
809 tableDef
->border
[borderSide
].color
= info
->rtfParam
;
812 case RTFBorderTypeCell
:
813 if (tableDef
&& tableDef
->numCellsDefined
< MAX_TABLE_CELLS
) {
814 tableDef
->cells
[tableDef
->numCellsDefined
].border
[borderSide
].color
= info
->rtfParam
;
822 RTFFlushOutputBuffer(info
);
823 /* FIXME too slow ? how come ?*/
824 ME_SetSelectionParaFormat(info
->editor
, &fmt
);
828 void ME_RTFTblAttrHook(RTF_Info
*info
)
830 switch (info
->rtfMinor
)
834 if (!info
->editor
->bEmulateVersion10
) /* v4.1 */
835 info
->borderType
= 0; /* Not sure */
836 else /* v1.0 - 3.0 */
837 info
->borderType
= RTFBorderRowTop
;
838 if (!info
->tableDef
) {
839 info
->tableDef
= ME_MakeTableDef(info
->editor
);
841 ME_InitTableDef(info
->editor
, info
->tableDef
);
850 info
->tableDef
= ME_MakeTableDef(info
->editor
);
852 cellNum
= info
->tableDef
->numCellsDefined
;
853 if (cellNum
>= MAX_TABLE_CELLS
)
855 info
->tableDef
->cells
[cellNum
].rightBoundary
= info
->rtfParam
;
856 if (cellNum
< MAX_TAB_STOPS
) {
857 /* Tab stops were used to store cell positions before v4.1 but v4.1
858 * still seems to set the tabstops without using them. */
859 ME_DisplayItem
*para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
860 PARAFORMAT2
*pFmt
= para
->member
.para
.pFmt
;
861 pFmt
->rgxTabs
[cellNum
] &= ~0x00FFFFFF;
862 pFmt
->rgxTabs
[cellNum
] = 0x00FFFFFF & info
->rtfParam
;
864 info
->tableDef
->numCellsDefined
++;
868 info
->borderType
= RTFBorderRowTop
;
871 info
->borderType
= RTFBorderRowLeft
;
873 case rtfRowBordBottom
:
874 info
->borderType
= RTFBorderRowBottom
;
876 case rtfRowBordRight
:
877 info
->borderType
= RTFBorderRowRight
;
880 info
->borderType
= RTFBorderCellTop
;
882 case rtfCellBordLeft
:
883 info
->borderType
= RTFBorderCellLeft
;
885 case rtfCellBordBottom
:
886 info
->borderType
= RTFBorderCellBottom
;
888 case rtfCellBordRight
:
889 info
->borderType
= RTFBorderCellRight
;
893 info
->tableDef
->gapH
= info
->rtfParam
;
897 info
->tableDef
->leftEdge
= info
->rtfParam
;
902 void ME_RTFSpecialCharHook(RTF_Info
*info
)
904 RTFTable
*tableDef
= info
->tableDef
;
905 switch (info
->rtfMinor
)
908 if (info
->editor
->bEmulateVersion10
) /* v1.0 - v3.0 */
910 /* else fall through since v4.1 treats rtfNestCell and rtfCell the same */
914 RTFFlushOutputBuffer(info
);
915 if (!info
->editor
->bEmulateVersion10
) { /* v4.1 */
916 if (tableDef
->tableRowStart
)
918 if (!info
->nestingLevel
&&
919 tableDef
->tableRowStart
->member
.para
.nFlags
& MEPF_ROWEND
)
921 ME_DisplayItem
*para
= tableDef
->tableRowStart
;
922 para
= para
->member
.para
.next_para
;
923 para
= ME_InsertTableRowStartAtParagraph(info
->editor
, para
);
924 tableDef
->tableRowStart
= para
;
925 info
->nestingLevel
= 1;
927 ME_InsertTableCellFromCursor(info
->editor
);
929 } else { /* v1.0 - v3.0 */
930 ME_DisplayItem
*para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
931 PARAFORMAT2
*pFmt
= para
->member
.para
.pFmt
;
932 if (pFmt
->dwMask
& PFM_TABLE
&& pFmt
->wEffects
& PFE_TABLE
&&
933 tableDef
->numCellsInserted
< tableDef
->numCellsDefined
)
936 ME_InsertTextFromCursor(info
->editor
, 0, &tab
, 1, info
->style
);
937 tableDef
->numCellsInserted
++;
942 if (info
->editor
->bEmulateVersion10
) /* v1.0 - v3.0 */
944 /* else fall through since v4.1 treats rtfNestRow and rtfRow the same */
947 ME_DisplayItem
*para
, *cell
, *run
;
952 RTFFlushOutputBuffer(info
);
953 if (!info
->editor
->bEmulateVersion10
) { /* v4.1 */
954 if (!tableDef
->tableRowStart
)
956 if (!info
->nestingLevel
&&
957 tableDef
->tableRowStart
->member
.para
.nFlags
& MEPF_ROWEND
)
959 para
= tableDef
->tableRowStart
;
960 para
= para
->member
.para
.next_para
;
961 para
= ME_InsertTableRowStartAtParagraph(info
->editor
, para
);
962 tableDef
->tableRowStart
= para
;
963 info
->nestingLevel
++;
965 para
= tableDef
->tableRowStart
;
966 cell
= ME_FindItemFwd(para
, diCell
);
967 assert(cell
&& !cell
->member
.cell
.prev_cell
);
968 if (tableDef
->numCellsDefined
< 1)
970 /* 2000 twips appears to be the cell size that native richedit uses
971 * when no cell sizes are specified. */
972 const int defaultCellSize
= 2000;
973 int nRightBoundary
= defaultCellSize
;
974 cell
->member
.cell
.nRightBoundary
= nRightBoundary
;
975 while (cell
->member
.cell
.next_cell
) {
976 cell
= cell
->member
.cell
.next_cell
;
977 nRightBoundary
+= defaultCellSize
;
978 cell
->member
.cell
.nRightBoundary
= nRightBoundary
;
980 para
= ME_InsertTableCellFromCursor(info
->editor
);
981 cell
= para
->member
.para
.pCell
;
982 cell
->member
.cell
.nRightBoundary
= nRightBoundary
;
984 for (i
= 0; i
< tableDef
->numCellsDefined
; i
++)
986 RTFCell
*cellDef
= &tableDef
->cells
[i
];
987 cell
->member
.cell
.nRightBoundary
= cellDef
->rightBoundary
;
988 ME_ApplyBorderProperties(info
, &cell
->member
.cell
.border
,
990 cell
= cell
->member
.cell
.next_cell
;
993 para
= ME_InsertTableCellFromCursor(info
->editor
);
994 cell
= para
->member
.para
.pCell
;
997 /* Cell for table row delimiter is empty */
998 cell
->member
.cell
.nRightBoundary
= tableDef
->cells
[i
-1].rightBoundary
;
1001 run
= ME_FindItemFwd(cell
, diRun
);
1002 if (info
->editor
->pCursors
[0].pRun
!= run
||
1003 info
->editor
->pCursors
[0].nOffset
)
1006 /* Delete inserted cells that aren't defined. */
1007 info
->editor
->pCursors
[1].pRun
= run
;
1008 info
->editor
->pCursors
[1].nOffset
= 0;
1009 nOfs
= ME_GetCursorOfs(info
->editor
, 1);
1010 nChars
= ME_GetCursorOfs(info
->editor
, 0) - nOfs
;
1011 ME_InternalDeleteText(info
->editor
, nOfs
, nChars
, TRUE
);
1014 para
= ME_InsertTableRowEndFromCursor(info
->editor
);
1015 para
->member
.para
.pFmt
->dxOffset
= abs(info
->tableDef
->gapH
);
1016 para
->member
.para
.pFmt
->dxStartIndent
= info
->tableDef
->leftEdge
;
1017 ME_ApplyBorderProperties(info
, ¶
->member
.para
.border
,
1019 info
->nestingLevel
--;
1020 if (!info
->nestingLevel
)
1022 if (info
->canInheritInTbl
) {
1023 tableDef
->tableRowStart
= para
;
1025 while (info
->tableDef
) {
1026 tableDef
= info
->tableDef
;
1027 info
->tableDef
= tableDef
->parent
;
1028 heap_free(tableDef
);
1032 info
->tableDef
= tableDef
->parent
;
1033 heap_free(tableDef
);
1035 } else { /* v1.0 - v3.0 */
1037 ME_DisplayItem
*para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
1038 PARAFORMAT2
*pFmt
= para
->member
.para
.pFmt
;
1039 pFmt
->dxOffset
= info
->tableDef
->gapH
;
1040 pFmt
->dxStartIndent
= info
->tableDef
->leftEdge
;
1042 para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
1043 ME_ApplyBorderProperties(info
, ¶
->member
.para
.border
,
1045 while (tableDef
->numCellsInserted
< tableDef
->numCellsDefined
)
1048 ME_InsertTextFromCursor(info
->editor
, 0, &tab
, 1, info
->style
);
1049 tableDef
->numCellsInserted
++;
1051 pFmt
->cTabCount
= min(tableDef
->numCellsDefined
, MAX_TAB_STOPS
);
1052 if (!tableDef
->numCellsDefined
)
1053 pFmt
->wEffects
&= ~PFE_TABLE
;
1054 ME_InsertTextFromCursor(info
->editor
, 0, &endl
, 1, info
->style
);
1055 tableDef
->numCellsInserted
= 0;
1061 if (info
->editor
->bEmulateVersion10
) { /* v1.0 - 3.0 */
1062 ME_DisplayItem
*para
;
1064 RTFFlushOutputBuffer(info
);
1065 para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
1066 pFmt
= para
->member
.para
.pFmt
;
1067 if (pFmt
->dwMask
& PFM_TABLE
&& pFmt
->wEffects
& PFE_TABLE
)
1069 /* rtfPar is treated like a space within a table. */
1070 info
->rtfClass
= rtfText
;
1071 info
->rtfMajor
= ' ';
1073 else if (info
->rtfMinor
== rtfPar
&& tableDef
)
1074 tableDef
->numCellsInserted
= 0;
1080 static BOOL
ME_RTFInsertOleObject(RTF_Info
*info
, HENHMETAFILE hemf
, HBITMAP hbmp
,
1083 LPOLEOBJECT lpObject
= NULL
;
1084 LPSTORAGE lpStorage
= NULL
;
1085 LPOLECLIENTSITE lpClientSite
= NULL
;
1086 LPDATAOBJECT lpDataObject
= NULL
;
1087 LPOLECACHE lpOleCache
= NULL
;
1096 stgm
.tymed
= TYMED_ENHMF
;
1097 stgm
.u
.hEnhMetaFile
= hemf
;
1098 fm
.cfFormat
= CF_ENHMETAFILE
;
1102 stgm
.tymed
= TYMED_GDI
;
1103 stgm
.u
.hBitmap
= hbmp
;
1104 fm
.cfFormat
= CF_BITMAP
;
1106 stgm
.pUnkForRelease
= NULL
;
1109 fm
.dwAspect
= DVASPECT_CONTENT
;
1111 fm
.tymed
= stgm
.tymed
;
1113 if (!info
->lpRichEditOle
)
1115 CreateIRichEditOle(info
->editor
, (VOID
**)&info
->lpRichEditOle
);
1118 if (OleCreateDefaultHandler(&CLSID_NULL
, NULL
, &IID_IOleObject
, (void**)&lpObject
) == S_OK
&&
1120 /* FIXME: enable it when rich-edit properly implements this method */
1121 IRichEditOle_GetClientSite(info
->lpRichEditOle
, &lpClientSite
) == S_OK
&&
1122 IOleObject_SetClientSite(lpObject
, lpClientSite
) == S_OK
&&
1124 IOleObject_GetUserClassID(lpObject
, &clsid
) == S_OK
&&
1125 IOleObject_QueryInterface(lpObject
, &IID_IOleCache
, (void**)&lpOleCache
) == S_OK
&&
1126 IOleCache_Cache(lpOleCache
, &fm
, 0, &conn
) == S_OK
&&
1127 IOleObject_QueryInterface(lpObject
, &IID_IDataObject
, (void**)&lpDataObject
) == S_OK
&&
1128 IDataObject_SetData(lpDataObject
, &fm
, &stgm
, TRUE
) == S_OK
)
1132 reobject
.cbStruct
= sizeof(reobject
);
1133 reobject
.cp
= REO_CP_SELECTION
;
1134 reobject
.clsid
= clsid
;
1135 reobject
.poleobj
= lpObject
;
1136 reobject
.pstg
= lpStorage
;
1137 reobject
.polesite
= lpClientSite
;
1138 /* convert from twips to .01 mm */
1139 reobject
.sizel
.cx
= MulDiv(sz
->cx
, 254, 144);
1140 reobject
.sizel
.cy
= MulDiv(sz
->cy
, 254, 144);
1141 reobject
.dvaspect
= DVASPECT_CONTENT
;
1142 reobject
.dwFlags
= 0; /* FIXME */
1143 reobject
.dwUser
= 0;
1145 /* FIXME: could be simpler */
1146 ret
= IRichEditOle_InsertObject(info
->lpRichEditOle
, &reobject
) == S_OK
;
1149 if (lpObject
) IOleObject_Release(lpObject
);
1150 if (lpClientSite
) IOleClientSite_Release(lpClientSite
);
1151 if (lpStorage
) IStorage_Release(lpStorage
);
1152 if (lpDataObject
) IDataObject_Release(lpDataObject
);
1153 if (lpOleCache
) IOleCache_Release(lpOleCache
);
1158 static void ME_RTFReadPictGroup(RTF_Info
*info
)
1161 BYTE
* buffer
= NULL
;
1162 unsigned bufsz
, bufidx
;
1168 enum gfxkind
{gfx_unknown
= 0, gfx_enhmetafile
, gfx_metafile
, gfx_dib
} gfx
= gfx_unknown
;
1171 if (info
->rtfClass
== rtfEOF
)
1174 /* fetch picture type */
1175 if (RTFCheckMM (info
, rtfPictAttr
, rtfWinMetafile
))
1177 mfp
.mm
= info
->rtfParam
;
1180 else if (RTFCheckMM (info
, rtfPictAttr
, rtfDevIndBitmap
))
1182 if (info
->rtfParam
!= 0) FIXME("dibitmap should be 0 (%d)\n", info
->rtfParam
);
1185 else if (RTFCheckMM (info
, rtfPictAttr
, rtfEmfBlip
))
1187 gfx
= gfx_enhmetafile
;
1191 FIXME("%d %d\n", info
->rtfMajor
, info
->rtfMinor
);
1195 /* fetch picture attributes */
1199 if (info
->rtfClass
== rtfEOF
)
1201 if (info
->rtfClass
== rtfText
)
1203 if (!RTFCheckCM (info
, rtfControl
, rtfPictAttr
))
1205 ERR("Expected picture attribute (%d %d)\n",
1206 info
->rtfClass
, info
->rtfMajor
);
1209 else if (RTFCheckMM (info
, rtfPictAttr
, rtfPicWid
))
1211 if (gfx
== gfx_metafile
) mfp
.xExt
= info
->rtfParam
;
1213 else if (RTFCheckMM (info
, rtfPictAttr
, rtfPicHt
))
1215 if (gfx
== gfx_metafile
) mfp
.yExt
= info
->rtfParam
;
1217 else if (RTFCheckMM (info
, rtfPictAttr
, rtfPicGoalWid
))
1218 sz
.cx
= info
->rtfParam
;
1219 else if (RTFCheckMM (info
, rtfPictAttr
, rtfPicGoalHt
))
1220 sz
.cy
= info
->rtfParam
;
1222 FIXME("Non supported attribute: %d %d %d\n", info
->rtfClass
, info
->rtfMajor
, info
->rtfMinor
);
1224 /* fetch picture data */
1227 buffer
= HeapAlloc(GetProcessHeap(), 0, bufsz
);
1228 val
= info
->rtfMajor
;
1229 for (flip
= TRUE
;; flip
= !flip
)
1232 if (info
->rtfClass
== rtfEOF
)
1234 HeapFree(GetProcessHeap(), 0, buffer
);
1235 return; /* Warn ?? */
1237 if (RTFCheckCM(info
, rtfGroup
, rtfEndGroup
))
1239 if (info
->rtfClass
!= rtfText
) goto skip_group
;
1242 if (bufidx
>= bufsz
&&
1243 !(buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
, bufsz
+= 1024)))
1245 buffer
[bufidx
++] = RTFCharToHex(val
) * 16 + RTFCharToHex(info
->rtfMajor
);
1248 val
= info
->rtfMajor
;
1250 if (flip
) FIXME("wrong hex string\n");
1254 case gfx_enhmetafile
:
1255 if ((hemf
= SetEnhMetaFileBits(bufidx
, buffer
)))
1256 ME_RTFInsertOleObject(info
, hemf
, NULL
, &sz
);
1259 if ((hemf
= SetWinMetaFileBits(bufidx
, buffer
, NULL
, &mfp
)))
1260 ME_RTFInsertOleObject(info
, hemf
, NULL
, &sz
);
1264 BITMAPINFO
* bi
= (BITMAPINFO
*)buffer
;
1266 unsigned nc
= bi
->bmiHeader
.biClrUsed
;
1268 /* not quite right, especially for bitfields type of compression */
1269 if (!nc
&& bi
->bmiHeader
.biBitCount
<= 8)
1270 nc
= 1 << bi
->bmiHeader
.biBitCount
;
1271 if ((hbmp
= CreateDIBitmap(hdc
, &bi
->bmiHeader
,
1272 CBM_INIT
, (char*)(bi
+ 1) + nc
* sizeof(RGBQUAD
),
1273 bi
, DIB_RGB_COLORS
)))
1274 ME_RTFInsertOleObject(info
, NULL
, hbmp
, &sz
);
1281 HeapFree(GetProcessHeap(), 0, buffer
);
1282 RTFRouteToken (info
); /* feed "}" back to router */
1285 HeapFree(GetProcessHeap(), 0, buffer
);
1287 RTFRouteToken(info
); /* feed "}" back to router */
1290 /* for now, lookup the \result part and use it, whatever the object */
1291 static void ME_RTFReadObjectGroup(RTF_Info
*info
)
1296 if (info
->rtfClass
== rtfEOF
)
1298 if (RTFCheckCM(info
, rtfGroup
, rtfEndGroup
))
1300 if (RTFCheckCM(info
, rtfGroup
, rtfBeginGroup
))
1303 if (info
->rtfClass
== rtfEOF
)
1305 if (RTFCheckCMM(info
, rtfControl
, rtfDestination
, rtfObjResult
))
1309 while (RTFGetToken (info
) != rtfEOF
)
1311 if (info
->rtfClass
== rtfGroup
)
1313 if (info
->rtfMajor
== rtfBeginGroup
) level
++;
1314 else if (info
->rtfMajor
== rtfEndGroup
&& --level
< 0) break;
1316 RTFRouteToken(info
);
1319 else RTFSkipGroup(info
);
1322 if (!RTFCheckCM (info
, rtfControl
, rtfObjAttr
))
1324 FIXME("Non supported attribute: %d %d %d\n", info
->rtfClass
, info
->rtfMajor
, info
->rtfMinor
);
1328 RTFRouteToken(info
); /* feed "}" back to router */
1331 static void ME_RTFReadHook(RTF_Info
*info
)
1333 switch(info
->rtfClass
)
1336 switch(info
->rtfMajor
)
1339 if (info
->stackTop
< maxStack
) {
1340 info
->stack
[info
->stackTop
].fmt
= info
->style
->fmt
;
1341 info
->stack
[info
->stackTop
].codePage
= info
->codePage
;
1342 info
->stack
[info
->stackTop
].unicodeLength
= info
->unicodeLength
;
1345 info
->styleChanged
= FALSE
;
1350 RTFFlushOutputBuffer(info
);
1352 if (info
->stackTop
<=0) {
1353 info
->rtfClass
= rtfEOF
;
1356 assert(info
->stackTop
>= 0);
1357 if (info
->styleChanged
)
1359 /* FIXME too slow ? how come ? */
1360 s
= ME_ApplyStyle(info
->style
, &info
->stack
[info
->stackTop
].fmt
);
1361 ME_ReleaseStyle(info
->style
);
1363 info
->codePage
= info
->stack
[info
->stackTop
].codePage
;
1364 info
->unicodeLength
= info
->stack
[info
->stackTop
].unicodeLength
;
1374 ME_StreamInFill(ME_InStream
*stream
)
1376 stream
->editstream
->dwError
= stream
->editstream
->pfnCallback(stream
->editstream
->dwCookie
,
1377 (BYTE
*)stream
->buffer
,
1378 sizeof(stream
->buffer
),
1379 (LONG
*)&stream
->dwSize
);
1383 static LRESULT
ME_StreamIn(ME_TextEditor
*editor
, DWORD format
, EDITSTREAM
*stream
, BOOL stripLastCR
)
1387 int from
, to
, to2
, nUndoMode
;
1388 int nEventMask
= editor
->nEventMask
;
1389 ME_InStream inStream
;
1390 BOOL invalidRTF
= FALSE
;
1392 TRACE("stream==%p hWnd==%p format==0x%X\n", stream
, editor
->hWnd
, format
);
1393 editor
->nEventMask
= 0;
1395 ME_GetSelection(editor
, &from
, &to
);
1396 if ((format
& SFF_SELECTION
) && (editor
->mode
& TM_RICHTEXT
)) {
1397 style
= ME_GetSelectionInsertStyle(editor
);
1399 ME_InternalDeleteText(editor
, from
, to
-from
, FALSE
);
1401 /* Don't insert text at the end of the table row */
1402 if (!editor
->bEmulateVersion10
) { /* v4.1 */
1403 ME_DisplayItem
*para
= ME_GetParagraph(editor
->pCursors
->pRun
);
1404 if (para
->member
.para
.nFlags
& MEPF_ROWEND
)
1406 para
= para
->member
.para
.next_para
;
1407 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
1408 editor
->pCursors
[0].nOffset
= 0;
1410 if (para
->member
.para
.nFlags
& MEPF_ROWSTART
)
1412 para
= para
->member
.para
.next_para
;
1413 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
1414 editor
->pCursors
[0].nOffset
= 0;
1416 editor
->pCursors
[1] = editor
->pCursors
[0];
1417 } else { /* v1.0 - 3.0 */
1418 if (editor
->pCursors
[0].pRun
->member
.run
.nFlags
& MERF_ENDPARA
&&
1419 ME_IsInTable(editor
->pCursors
[0].pRun
))
1424 ME_DisplayItem
*para_item
;
1425 style
= editor
->pBuffer
->pDefaultStyle
;
1426 ME_AddRefStyle(style
);
1427 SendMessageA(editor
->hWnd
, EM_SETSEL
, 0, 0);
1428 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
), FALSE
);
1430 ME_ClearTempStyle(editor
);
1432 para_item
= ME_GetParagraph(editor
->pCursors
[0].pRun
);
1433 ME_SetDefaultParaFormat(para_item
->member
.para
.pFmt
);
1437 /* Back up undo mode to a local variable */
1438 nUndoMode
= editor
->nUndoMode
;
1440 /* Only create an undo if SFF_SELECTION is set */
1441 if (!(format
& SFF_SELECTION
))
1442 editor
->nUndoMode
= umIgnore
;
1444 inStream
.editstream
= stream
;
1445 inStream
.editstream
->dwError
= 0;
1446 inStream
.dwSize
= 0;
1447 inStream
.dwUsed
= 0;
1449 if (format
& SF_RTF
)
1451 /* Check if it's really RTF, and if it is not, use plain text */
1452 ME_StreamInFill(&inStream
);
1453 if (!inStream
.editstream
->dwError
)
1455 if ((!editor
->bEmulateVersion10
&& strncmp(inStream
.buffer
, "{\\rtf", 5) && strncmp(inStream
.buffer
, "{\\urtf", 6))
1456 || (editor
->bEmulateVersion10
&& *inStream
.buffer
!= '{'))
1459 inStream
.editstream
->dwError
= -16;
1464 if (!invalidRTF
&& !inStream
.editstream
->dwError
)
1466 if (format
& SF_RTF
) {
1467 /* setup the RTF parser */
1468 memset(&parser
, 0, sizeof parser
);
1469 RTFSetEditStream(&parser
, &inStream
);
1470 parser
.rtfFormat
= format
&(SF_TEXT
|SF_RTF
);
1471 parser
.hwndEdit
= editor
->hWnd
;
1472 parser
.editor
= editor
;
1473 parser
.style
= style
;
1474 WriterInit(&parser
);
1476 RTFSetReadHook(&parser
, ME_RTFReadHook
);
1477 RTFSetDestinationCallback(&parser
, rtfPict
, ME_RTFReadPictGroup
);
1478 RTFSetDestinationCallback(&parser
, rtfObject
, ME_RTFReadObjectGroup
);
1479 if (!parser
.editor
->bEmulateVersion10
) /* v4.1 */
1481 RTFSetDestinationCallback(&parser
, rtfNoNestTables
, RTFSkipGroup
);
1482 RTFSetDestinationCallback(&parser
, rtfNestTableProps
, RTFReadGroup
);
1486 /* do the parsing */
1488 RTFFlushOutputBuffer(&parser
);
1489 if (!editor
->bEmulateVersion10
) { /* v4.1 */
1490 if (parser
.tableDef
&& parser
.tableDef
->tableRowStart
&&
1491 (parser
.nestingLevel
> 0 || parser
.canInheritInTbl
))
1493 /* Delete any incomplete table row at the end of the rich text. */
1495 ME_DisplayItem
*pCell
;
1496 ME_DisplayItem
*para
;
1498 parser
.rtfMinor
= rtfRow
;
1499 /* Complete the table row before deleting it.
1500 * By doing it this way we will have the current paragraph format set
1501 * properly to reflect that is not in the complete table, and undo items
1502 * will be added for this change to the current paragraph format. */
1503 if (parser
.nestingLevel
> 0)
1505 while (parser
.nestingLevel
> 1)
1506 ME_RTFSpecialCharHook(&parser
); /* Decrements nestingLevel */
1507 para
= parser
.tableDef
->tableRowStart
;
1508 ME_RTFSpecialCharHook(&parser
);
1510 para
= parser
.tableDef
->tableRowStart
;
1511 ME_RTFSpecialCharHook(&parser
);
1512 assert(para
->member
.para
.nFlags
& MEPF_ROWEND
);
1513 para
= para
->member
.para
.next_para
;
1515 pCell
= para
->member
.para
.pCell
;
1517 editor
->pCursors
[1].pRun
= ME_FindItemFwd(para
, diRun
);
1518 editor
->pCursors
[1].nOffset
= 0;
1519 nOfs
= ME_GetCursorOfs(editor
, 1);
1520 nChars
= ME_GetCursorOfs(editor
, 0) - nOfs
;
1521 ME_InternalDeleteText(editor
, nOfs
, nChars
, TRUE
);
1522 if (parser
.tableDef
)
1523 parser
.tableDef
->tableRowStart
= NULL
;
1526 ME_CheckTablesForCorruption(editor
);
1527 RTFDestroy(&parser
);
1528 if (parser
.lpRichEditOle
)
1529 IRichEditOle_Release(parser
.lpRichEditOle
);
1531 if (!inStream
.editstream
->dwError
&& parser
.stackTop
> 0)
1532 inStream
.editstream
->dwError
= HRESULT_FROM_WIN32(ERROR_HANDLE_EOF
);
1534 /* Remove last line break, as mandated by tests. This is not affected by
1535 CR/LF counters, since RTF streaming presents only \para tokens, which
1536 are converted according to the standard rules: \r for 2.0, \r\n for 1.0
1540 ME_GetSelection(editor
, &newfrom
, &newto
);
1541 if (newto
> to
+ (editor
->bEmulateVersion10
? 1 : 0)) {
1542 WCHAR lastchar
[3] = {'\0', '\0'};
1543 int linebreakSize
= editor
->bEmulateVersion10
? 2 : 1;
1545 ME_GetTextW(editor
, lastchar
, newto
- linebreakSize
, linebreakSize
, 0);
1546 if (lastchar
[0] == '\r' && (lastchar
[1] == '\n' || lastchar
[1] == '\0')) {
1547 ME_InternalDeleteText(editor
, newto
- linebreakSize
, linebreakSize
, FALSE
);
1552 style
= parser
.style
;
1554 else if (format
& SF_TEXT
)
1555 ME_StreamInText(editor
, format
, &inStream
, style
);
1557 ERR("EM_STREAMIN without SF_TEXT or SF_RTF\n");
1558 ME_GetSelection(editor
, &to
, &to2
);
1559 /* put the cursor at the top */
1560 if (!(format
& SFF_SELECTION
))
1561 SendMessageA(editor
->hWnd
, EM_SETSEL
, 0, 0);
1564 /* Restore saved undo mode */
1565 editor
->nUndoMode
= nUndoMode
;
1567 /* even if we didn't add an undo, we need to commit anything on the stack */
1568 ME_CommitUndo(editor
);
1570 /* If SFF_SELECTION isn't set, delete any undos from before we started too */
1571 if (!(format
& SFF_SELECTION
))
1572 ME_EmptyUndoStack(editor
);
1574 ME_ReleaseStyle(style
);
1575 editor
->nEventMask
= nEventMask
;
1576 ME_UpdateRepaint(editor
);
1577 if (!(format
& SFF_SELECTION
)) {
1578 ME_ClearTempStyle(editor
);
1580 HideCaret(editor
->hWnd
);
1581 ME_MoveCaret(editor
);
1582 ShowCaret(editor
->hWnd
);
1583 ME_SendSelChange(editor
);
1584 ME_SendRequestResize(editor
, FALSE
);
1590 typedef struct tagME_RTFStringStreamStruct
1595 } ME_RTFStringStreamStruct
;
1597 static DWORD CALLBACK
ME_ReadFromRTFString(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
1599 ME_RTFStringStreamStruct
*pStruct
= (ME_RTFStringStreamStruct
*)dwCookie
;
1602 count
= min(cb
, pStruct
->length
- pStruct
->pos
);
1603 memmove(lpBuff
, pStruct
->string
+ pStruct
->pos
, count
);
1604 pStruct
->pos
+= count
;
1610 ME_StreamInRTFString(ME_TextEditor
*editor
, BOOL selection
, char *string
)
1613 ME_RTFStringStreamStruct data
;
1615 data
.string
= string
;
1616 data
.length
= strlen(string
);
1618 es
.dwCookie
= (DWORD
)&data
;
1619 es
.pfnCallback
= ME_ReadFromRTFString
;
1620 ME_StreamIn(editor
, SF_RTF
| (selection
? SFF_SELECTION
: 0), &es
, FALSE
);
1625 ME_FindItemAtOffset(ME_TextEditor
*editor
, ME_DIType nItemType
, int nOffset
, int *nItemOffset
)
1627 ME_DisplayItem
*item
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
1630 while (item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= nOffset
)
1631 item
= ME_FindItemFwd(item
, diParagraph
);
1636 nOffset
-= item
->member
.para
.nCharOfs
;
1637 if (nItemType
== diParagraph
) {
1639 *nItemOffset
= nOffset
;
1644 item
= ME_FindItemFwd(item
, diRun
);
1645 runLength
= ME_StrLen(item
->member
.run
.strText
);
1646 if (item
->member
.run
.nFlags
& MERF_ENDPARA
)
1647 runLength
= item
->member
.run
.nCR
+ item
->member
.run
.nLF
;
1648 } while (item
&& (item
->member
.run
.nCharOfs
+ runLength
<= nOffset
));
1650 nOffset
-= item
->member
.run
.nCharOfs
;
1652 /* Special case: nOffset may not point exactly at the division between the
1653 \r and the \n in 1.0 emulation. If such a case happens, it is sent
1654 into the next run, if one exists
1656 if ( item
->member
.run
.nFlags
& MERF_ENDPARA
1657 && nOffset
== item
->member
.run
.nCR
1658 && item
->member
.run
.nLF
> 0) {
1659 ME_DisplayItem
*nextItem
;
1660 nextItem
= ME_FindItemFwd(item
, diRun
);
1667 *nItemOffset
= nOffset
;
1674 ME_FindText(ME_TextEditor
*editor
, DWORD flags
, const CHARRANGE
*chrg
, const WCHAR
*text
, CHARRANGE
*chrgText
)
1676 const int nLen
= lstrlenW(text
);
1677 const int nTextLen
= ME_GetTextLength(editor
);
1680 ME_DisplayItem
*item
;
1681 ME_DisplayItem
*para
;
1682 WCHAR wLastChar
= ' ';
1684 TRACE("flags==0x%08x, chrg->cpMin==%d, chrg->cpMax==%d text==%s\n",
1685 flags
, chrg
->cpMin
, chrg
->cpMax
, debugstr_w(text
));
1687 if (flags
& ~(FR_DOWN
| FR_MATCHCASE
| FR_WHOLEWORD
))
1688 FIXME("Flags 0x%08x not implemented\n",
1689 flags
& ~(FR_DOWN
| FR_MATCHCASE
| FR_WHOLEWORD
));
1692 if (chrg
->cpMax
== -1)
1695 nMax
= chrg
->cpMax
> nTextLen
? nTextLen
: chrg
->cpMax
;
1697 /* In 1.0 emulation, if cpMax reaches end of text, add the FR_DOWN flag */
1698 if (editor
->bEmulateVersion10
&& nMax
== nTextLen
)
1703 /* In 1.0 emulation, cpMin must always be no greater than cpMax */
1704 if (editor
->bEmulateVersion10
&& nMax
< nMin
)
1708 chrgText
->cpMin
= -1;
1709 chrgText
->cpMax
= -1;
1714 /* when searching up, if cpMin < cpMax, then instead of searching
1715 * on [cpMin,cpMax], we search on [0,cpMin], otherwise, search on
1716 * [cpMax, cpMin]. The exception is when cpMax is -1, in which
1717 * case, it is always bigger than cpMin.
1719 if (!editor
->bEmulateVersion10
&& !(flags
& FR_DOWN
))
1723 nMax
= nMin
> nTextLen
? nTextLen
: nMin
;
1724 if (nMin
< nSwap
|| chrg
->cpMax
== -1)
1730 if (!nLen
|| nMin
< 0 || nMax
< 0 || nMax
< nMin
)
1733 chrgText
->cpMin
= chrgText
->cpMax
= -1;
1737 if (flags
& FR_DOWN
) /* Forward search */
1739 /* If possible, find the character before where the search starts */
1740 if ((flags
& FR_WHOLEWORD
) && nMin
)
1743 item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
1747 chrgText
->cpMin
= chrgText
->cpMax
= -1;
1750 wLastChar
= item
->member
.run
.strText
->szData
[nStart
];
1754 item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
1758 chrgText
->cpMin
= chrgText
->cpMax
= -1;
1762 para
= ME_GetParagraph(item
);
1764 && para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
+ nLen
<= nMax
)
1766 ME_DisplayItem
*pCurItem
= item
;
1767 int nCurStart
= nStart
;
1770 while (pCurItem
&& ME_CharCompare(pCurItem
->member
.run
.strText
->szData
[nCurStart
+ nMatched
], text
[nMatched
], (flags
& FR_MATCHCASE
)))
1772 if ((flags
& FR_WHOLEWORD
) && isalnumW(wLastChar
))
1776 if (nMatched
== nLen
)
1778 ME_DisplayItem
*pNextItem
= pCurItem
;
1779 int nNextStart
= nCurStart
;
1782 /* Check to see if next character is a whitespace */
1783 if (flags
& FR_WHOLEWORD
)
1785 if (nCurStart
+ nMatched
== ME_StrLen(pCurItem
->member
.run
.strText
))
1787 pNextItem
= ME_FindItemFwd(pCurItem
, diRun
);
1788 nNextStart
= -nMatched
;
1792 wNextChar
= pNextItem
->member
.run
.strText
->szData
[nNextStart
+ nMatched
];
1796 if (isalnumW(wNextChar
))
1800 nStart
+= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
;
1803 chrgText
->cpMin
= nStart
;
1804 chrgText
->cpMax
= nStart
+ nLen
;
1806 TRACE("found at %d-%d\n", nStart
, nStart
+ nLen
);
1809 if (nCurStart
+ nMatched
== ME_StrLen(pCurItem
->member
.run
.strText
))
1811 pCurItem
= ME_FindItemFwd(pCurItem
, diRun
);
1812 para
= ME_GetParagraph(pCurItem
);
1813 nCurStart
= -nMatched
;
1817 wLastChar
= pCurItem
->member
.run
.strText
->szData
[nCurStart
+ nMatched
];
1822 if (nStart
== ME_StrLen(item
->member
.run
.strText
))
1824 item
= ME_FindItemFwd(item
, diRun
);
1825 para
= ME_GetParagraph(item
);
1830 else /* Backward search */
1832 /* If possible, find the character after where the search ends */
1833 if ((flags
& FR_WHOLEWORD
) && nMax
< nTextLen
- 1)
1836 item
= ME_FindItemAtOffset(editor
, diRun
, nEnd
, &nEnd
);
1840 chrgText
->cpMin
= chrgText
->cpMax
= -1;
1843 wLastChar
= item
->member
.run
.strText
->szData
[nEnd
];
1847 item
= ME_FindItemAtOffset(editor
, diRun
, nEnd
, &nEnd
);
1851 chrgText
->cpMin
= chrgText
->cpMax
= -1;
1855 para
= ME_GetParagraph(item
);
1858 && para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nEnd
- nLen
>= nMin
)
1860 ME_DisplayItem
*pCurItem
= item
;
1864 if (nCurEnd
- nMatched
== 0)
1866 pCurItem
= ME_FindItemBack(pCurItem
, diRun
);
1867 para
= ME_GetParagraph(pCurItem
);
1868 nCurEnd
= ME_StrLen(pCurItem
->member
.run
.strText
) + nMatched
;
1871 while (pCurItem
&& ME_CharCompare(pCurItem
->member
.run
.strText
->szData
[nCurEnd
- nMatched
- 1], text
[nLen
- nMatched
- 1], (flags
& FR_MATCHCASE
)))
1873 if ((flags
& FR_WHOLEWORD
) && isalnumW(wLastChar
))
1877 if (nMatched
== nLen
)
1879 ME_DisplayItem
*pPrevItem
= pCurItem
;
1880 int nPrevEnd
= nCurEnd
;
1883 /* Check to see if previous character is a whitespace */
1884 if (flags
& FR_WHOLEWORD
)
1886 if (nPrevEnd
- nMatched
== 0)
1888 pPrevItem
= ME_FindItemBack(pCurItem
, diRun
);
1890 nPrevEnd
= ME_StrLen(pPrevItem
->member
.run
.strText
) + nMatched
;
1894 wPrevChar
= pPrevItem
->member
.run
.strText
->szData
[nPrevEnd
- nMatched
- 1];
1898 if (isalnumW(wPrevChar
))
1902 nStart
= para
->member
.para
.nCharOfs
+ pCurItem
->member
.run
.nCharOfs
+ nCurEnd
- nMatched
;
1905 chrgText
->cpMin
= nStart
;
1906 chrgText
->cpMax
= nStart
+ nLen
;
1908 TRACE("found at %d-%d\n", nStart
, nStart
+ nLen
);
1911 if (nCurEnd
- nMatched
== 0)
1913 pCurItem
= ME_FindItemBack(pCurItem
, diRun
);
1914 /* Don't care about pCurItem becoming NULL here; it's already taken
1915 * care of in the exterior loop condition */
1916 para
= ME_GetParagraph(pCurItem
);
1917 nCurEnd
= ME_StrLen(pCurItem
->member
.run
.strText
) + nMatched
;
1921 wLastChar
= pCurItem
->member
.run
.strText
->szData
[nCurEnd
- nMatched
- 1];
1928 item
= ME_FindItemBack(item
, diRun
);
1929 para
= ME_GetParagraph(item
);
1930 nEnd
= ME_StrLen(item
->member
.run
.strText
);
1934 TRACE("not found\n");
1936 chrgText
->cpMin
= chrgText
->cpMax
= -1;
1940 /* helper to send a msg filter notification */
1942 ME_FilterEvent(ME_TextEditor
*editor
, UINT msg
, WPARAM
* wParam
, LPARAM
* lParam
)
1946 msgf
.nmhdr
.hwndFrom
= editor
->hWnd
;
1947 msgf
.nmhdr
.idFrom
= GetWindowLongW(editor
->hWnd
, GWLP_ID
);
1948 msgf
.nmhdr
.code
= EN_MSGFILTER
;
1951 msgf
.wParam
= *wParam
;
1952 msgf
.lParam
= *lParam
;
1953 if (SendMessageW(GetParent(editor
->hWnd
), WM_NOTIFY
, msgf
.nmhdr
.idFrom
, (LPARAM
)&msgf
))
1955 *wParam
= msgf
.wParam
;
1956 *lParam
= msgf
.lParam
;
1957 msgf
.wParam
= *wParam
;
1963 ME_KeyDown(ME_TextEditor
*editor
, WORD nKey
)
1965 BOOL ctrl_is_down
= GetKeyState(VK_CONTROL
) & 0x8000;
1966 BOOL shift_is_down
= GetKeyState(VK_SHIFT
) & 0x8000;
1968 if (nKey
!= VK_SHIFT
&& nKey
!= VK_CONTROL
&& nKey
!= VK_MENU
)
1969 editor
->nSelectionType
= stPosition
;
1977 editor
->nUDArrowX
= -1;
1983 ME_CommitUndo(editor
); /* End coalesced undos for typed characters */
1984 ME_ArrowKey(editor
, nKey
, shift_is_down
, ctrl_is_down
);
1988 editor
->nUDArrowX
= -1;
1989 /* FIXME backspace and delete aren't the same, they act different wrt paragraph style of the merged paragraph */
1990 if (GetWindowLongW(editor
->hWnd
, GWL_STYLE
) & ES_READONLY
)
1992 if (ME_IsSelection(editor
))
1994 ME_DeleteSelection(editor
);
1995 ME_CommitUndo(editor
);
1997 else if (nKey
== VK_DELETE
)
1999 /* Delete stops group typing.
2000 * (See MSDN remarks on EM_STOPGROUPTYPING message) */
2001 ME_DeleteTextAtCursor(editor
, 1, 1);
2002 ME_CommitUndo(editor
);
2004 else if (ME_ArrowKey(editor
, VK_LEFT
, FALSE
, FALSE
))
2006 BOOL bDeletionSucceeded
;
2007 /* Backspace can be grouped for a single undo */
2008 ME_ContinueCoalescingTransaction(editor
);
2009 bDeletionSucceeded
= ME_DeleteTextAtCursor(editor
, 1, 1);
2010 if (!bDeletionSucceeded
&& !editor
->bEmulateVersion10
) { /* v4.1 */
2011 /* Deletion was prevented so the cursor is moved back to where it was.
2012 * (e.g. this happens when trying to delete cell boundaries)
2014 ME_ArrowKey(editor
, VK_RIGHT
, FALSE
, FALSE
);
2016 ME_CommitCoalescingUndo(editor
);
2020 ME_MoveCursorFromTableRowStartParagraph(editor
);
2021 ME_UpdateSelectionLinkAttribute(editor
);
2022 ME_UpdateRepaint(editor
);
2023 ME_SendRequestResize(editor
, FALSE
);
2027 if (nKey
!= VK_SHIFT
&& nKey
!= VK_CONTROL
&& nKey
&& nKey
!= VK_MENU
)
2028 editor
->nUDArrowX
= -1;
2035 chf
.cbSize
= sizeof(chf
);
2037 ME_GetSelectionCharFormat(editor
, &chf
);
2038 ME_DumpStyleToBuf(&chf
, buf
);
2039 MessageBoxA(NULL
, buf
, "Style dump", MB_OK
);
2043 ME_CheckCharOffsets(editor
);
2050 /* Process the message and calculate the new click count.
2052 * returns: The click count if it is mouse down event, else returns 0. */
2053 static int ME_CalculateClickCount(HWND hWnd
, UINT msg
, WPARAM wParam
,
2056 static int clickNum
= 0;
2057 if (msg
< WM_MOUSEFIRST
|| msg
> WM_MOUSELAST
)
2060 if ((msg
== WM_LBUTTONDBLCLK
) ||
2061 (msg
== WM_RBUTTONDBLCLK
) ||
2062 (msg
== WM_MBUTTONDBLCLK
) ||
2063 (msg
== WM_XBUTTONDBLCLK
))
2065 msg
-= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
2068 if ((msg
== WM_LBUTTONDOWN
) ||
2069 (msg
== WM_RBUTTONDOWN
) ||
2070 (msg
== WM_MBUTTONDOWN
) ||
2071 (msg
== WM_XBUTTONDOWN
))
2073 static MSG prevClickMsg
;
2075 clickMsg
.hwnd
= hWnd
;
2076 clickMsg
.message
= msg
;
2077 clickMsg
.wParam
= wParam
;
2078 clickMsg
.lParam
= lParam
;
2079 clickMsg
.time
= GetMessageTime();
2080 clickMsg
.pt
.x
= (short)LOWORD(lParam
);
2081 clickMsg
.pt
.y
= (short)HIWORD(lParam
);
2082 if ((clickNum
!= 0) &&
2083 (clickMsg
.message
== prevClickMsg
.message
) &&
2084 (clickMsg
.hwnd
== prevClickMsg
.hwnd
) &&
2085 (clickMsg
.wParam
== prevClickMsg
.wParam
) &&
2086 (clickMsg
.time
- prevClickMsg
.time
< GetDoubleClickTime()) &&
2087 (abs(clickMsg
.pt
.x
- prevClickMsg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
2088 (abs(clickMsg
.pt
.y
- prevClickMsg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
2094 prevClickMsg
= clickMsg
;
2101 static BOOL
ME_SetCursor(ME_TextEditor
*editor
)
2106 DWORD messagePos
= GetMessagePos();
2107 pt
.x
= (short)LOWORD(messagePos
);
2108 pt
.y
= (short)HIWORD(messagePos
);
2109 ScreenToClient(editor
->hWnd
, &pt
);
2110 if ((GetWindowLongW(editor
->hWnd
, GWL_STYLE
) & ES_SELECTIONBAR
) &&
2111 (pt
.x
< editor
->selofs
||
2112 (editor
->nSelectionType
== stLine
&& GetCapture() == editor
->hWnd
)))
2117 offset
= ME_CharFromPos(editor
, pt
.x
, pt
.y
, &isExact
);
2120 if (editor
->AutoURLDetect_bEnable
)
2124 ME_CursorFromCharOfs(editor
, offset
, &cursor
);
2125 run
= &cursor
.pRun
->member
.run
;
2126 if (editor
->AutoURLDetect_bEnable
&&
2127 run
->style
->fmt
.dwMask
& CFM_LINK
&&
2128 run
->style
->fmt
.dwEffects
& CFE_LINK
)
2130 SetCursor(LoadCursorW(NULL
, (WCHAR
*)IDC_HAND
));
2134 if (ME_IsSelection(editor
))
2136 int selStart
, selEnd
;
2137 ME_GetSelection(editor
, &selStart
, &selEnd
);
2138 if (selStart
<= offset
&& selEnd
>= offset
) {
2139 SetCursor(LoadCursorW(NULL
, (WCHAR
*)IDC_ARROW
));
2144 SetCursor(LoadCursorW(NULL
, (WCHAR
*)IDC_IBEAM
));
2148 static BOOL
ME_ShowContextMenu(ME_TextEditor
*editor
, int x
, int y
)
2153 if(!editor
->lpOleCallback
)
2155 ME_GetSelection(editor
, &selrange
.cpMin
, &selrange
.cpMax
);
2156 if(selrange
.cpMin
== selrange
.cpMax
)
2157 seltype
|= SEL_EMPTY
;
2160 /* FIXME: Handle objects */
2161 seltype
|= SEL_TEXT
;
2162 if(selrange
.cpMax
-selrange
.cpMin
> 1)
2163 seltype
|= SEL_MULTICHAR
;
2165 if(SUCCEEDED(IRichEditOleCallback_GetContextMenu(editor
->lpOleCallback
, seltype
, NULL
, &selrange
, &menu
)))
2167 TrackPopupMenu(menu
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, GetParent(editor
->hWnd
), NULL
);
2173 ME_TextEditor
*ME_MakeEditor(HWND hWnd
) {
2174 ME_TextEditor
*ed
= ALLOC_OBJ(ME_TextEditor
);
2177 ed
->bEmulateVersion10
= FALSE
;
2178 ed
->pBuffer
= ME_MakeText();
2179 ed
->nZoomNumerator
= ed
->nZoomDenominator
= 0;
2180 ME_MakeFirstParagraph(ed
);
2181 /* The four cursors are for:
2182 * 0 - The position where the caret is shown
2183 * 1 - The anchored end of the selection (for normal selection)
2184 * 2 & 3 - The anchored start and end respectively for word, line,
2185 * or paragraph selection.
2188 ed
->pCursors
= ALLOC_N_OBJ(ME_Cursor
, ed
->nCursors
);
2189 ed
->pCursors
[0].pRun
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diRun
);
2190 ed
->pCursors
[0].nOffset
= 0;
2191 ed
->pCursors
[1].pRun
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diRun
);
2192 ed
->pCursors
[1].nOffset
= 0;
2193 ed
->pCursors
[2] = ed
->pCursors
[0];
2194 ed
->pCursors
[3] = ed
->pCursors
[1];
2195 ed
->nLastTotalLength
= ed
->nTotalLength
= 0;
2199 ed
->rgbBackColor
= -1;
2200 ed
->hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
2201 ed
->bCaretAtEnd
= FALSE
;
2203 ed
->nModifyStep
= 0;
2204 ed
->nTextLimit
= TEXT_LIMIT_DEFAULT
;
2205 ed
->pUndoStack
= ed
->pRedoStack
= ed
->pUndoStackBottom
= NULL
;
2206 ed
->nUndoStackSize
= 0;
2207 ed
->nUndoLimit
= STACK_SIZE_DEFAULT
;
2208 ed
->nUndoMode
= umAddToUndo
;
2209 ed
->nParagraphs
= 1;
2210 ed
->nLastSelStart
= ed
->nLastSelEnd
= 0;
2211 ed
->pLastSelStartPara
= ed
->pLastSelEndPara
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diParagraph
);
2213 ed
->bWordWrap
= (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_HSCROLL
) ? FALSE
: TRUE
;
2214 ed
->bHideSelection
= FALSE
;
2215 ed
->nInvalidOfs
= -1;
2216 ed
->pfnWordBreak
= NULL
;
2217 ed
->lpOleCallback
= NULL
;
2218 ed
->mode
= TM_RICHTEXT
| TM_MULTILEVELUNDO
| TM_MULTICODEPAGE
;
2219 ed
->AutoURLDetect_bEnable
= FALSE
;
2220 ed
->bHaveFocus
= FALSE
;
2221 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
2223 ed
->pFontCache
[i
].nRefs
= 0;
2224 ed
->pFontCache
[i
].nAge
= 0;
2225 ed
->pFontCache
[i
].hFont
= NULL
;
2228 ME_CheckCharOffsets(ed
);
2229 if (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_SELECTIONBAR
)
2230 ed
->selofs
= SELECTIONBAR_WIDTH
;
2233 ed
->nSelectionType
= stPosition
;
2235 if (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_PASSWORD
)
2236 ed
->cPasswordMask
= '*';
2238 ed
->cPasswordMask
= 0;
2240 ed
->notified_cr
.cpMin
= ed
->notified_cr
.cpMax
= 0;
2242 /* Default vertical scrollbar information */
2243 ed
->vert_si
.cbSize
= sizeof(SCROLLINFO
);
2244 ed
->vert_si
.nMin
= 0;
2245 ed
->vert_si
.nMax
= 0;
2246 ed
->vert_si
.nPage
= 0;
2247 ed
->vert_si
.nPos
= 0;
2249 OleInitialize(NULL
);
2254 typedef struct tagME_GlobalDestStruct
2258 } ME_GlobalDestStruct
;
2260 static DWORD CALLBACK
ME_ReadFromHGLOBALUnicode(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
2262 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
2267 pDest
= (WORD
*)lpBuff
;
2268 pSrc
= (WORD
*)GlobalLock(pData
->hData
);
2269 for (i
= 0; i
<cb
&& pSrc
[pData
->nLength
+i
]; i
++) {
2270 pDest
[i
] = pSrc
[pData
->nLength
+i
];
2272 pData
->nLength
+= i
;
2274 GlobalUnlock(pData
->hData
);
2278 static DWORD CALLBACK
ME_ReadFromHGLOBALRTF(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
2280 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
2285 pSrc
= (BYTE
*)GlobalLock(pData
->hData
);
2286 for (i
= 0; i
<cb
&& pSrc
[pData
->nLength
+i
]; i
++) {
2287 pDest
[i
] = pSrc
[pData
->nLength
+i
];
2289 pData
->nLength
+= i
;
2291 GlobalUnlock(pData
->hData
);
2296 void ME_DestroyEditor(ME_TextEditor
*editor
)
2298 ME_DisplayItem
*pFirst
= editor
->pBuffer
->pFirst
;
2299 ME_DisplayItem
*p
= pFirst
, *pNext
= NULL
;
2302 ME_ClearTempStyle(editor
);
2303 ME_EmptyUndoStack(editor
);
2306 ME_DestroyDisplayItem(p
);
2309 ME_ReleaseStyle(editor
->pBuffer
->pDefaultStyle
);
2310 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
2312 if (editor
->pFontCache
[i
].hFont
)
2313 DeleteObject(editor
->pFontCache
[i
].hFont
);
2315 if (editor
->rgbBackColor
!= -1)
2316 DeleteObject(editor
->hbrBackground
);
2317 if(editor
->lpOleCallback
)
2318 IUnknown_Release(editor
->lpOleCallback
);
2321 FREE_OBJ(editor
->pBuffer
);
2322 FREE_OBJ(editor
->pCursors
);
2327 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
2332 case DLL_PROCESS_ATTACH
:
2333 DisableThreadLibraryCalls(hinstDLL
);
2334 me_heap
= HeapCreate (0, 0x10000, 0);
2335 if (!ME_RegisterEditorClass(hinstDLL
)) return FALSE
;
2336 hLeft
= LoadCursorW(hinstDLL
, MAKEINTRESOURCEW(OCR_REVERSE
));
2340 case DLL_PROCESS_DETACH
:
2341 UnregisterClassW(RichEdit20W
, 0);
2342 UnregisterClassW(RichEdit50W
, 0);
2343 UnregisterClassA("RichEdit20A", 0);
2344 UnregisterClassA("RichEdit50A", 0);
2345 if (ME_ListBoxRegistered
)
2346 UnregisterClassW(REListBox20W
, 0);
2347 if (ME_ComboBoxRegistered
)
2348 UnregisterClassW(REComboBox20W
, 0);
2350 HeapDestroy (me_heap
);
2358 #define UNSUPPORTED_MSG(e) \
2360 FIXME(#e ": stub\n"); \
2361 return DefWindowProcW(hWnd, msg, wParam, lParam);
2363 static const char * const edit_messages
[] = {
2392 "EM_SETPASSWORDCHAR",
2393 "EM_EMPTYUNDOBUFFER",
2394 "EM_GETFIRSTVISIBLELINE",
2396 "EM_SETWORDBREAKPROC",
2397 "EM_GETWORDBREAKPROC",
2398 "EM_GETPASSWORDCHAR",
2406 static const char * const richedit_messages
[] = {
2411 "EM_EXLINEFROMCHAR",
2417 "EM_GETOLEINTERFACE",
2427 "EM_SETOLECALLBACK",
2429 "EM_SETTARGETDEVICE",
2437 "EM_GETWORDBREAKPROCEX",
2438 "EM_SETWORDBREAKPROCEX",
2440 "EM_UNKNOWN_USER_83",
2445 "EM_STOPGROUPTYPING",
2449 "EM_GETAUTOURLDETECT",
2452 "EM_GETTEXTLENGTHEX",
2455 "EM_UNKNOWN_USER_98",
2456 "EM_UNKNOWN_USER_99",
2457 "EM_SETPUNCTUATION",
2458 "EM_GETPUNCTUATION",
2459 "EM_SETWORDWRAPMODE",
2460 "EM_GETWORDWRAPMODE",
2466 "EM_UNKNOWN_USER_109",
2467 "EM_UNKNOWN_USER_110",
2468 "EM_UNKNOWN_USER_111",
2469 "EM_UNKNOWN_USER_112",
2470 "EM_UNKNOWN_USER_113",
2471 "EM_UNKNOWN_USER_114",
2472 "EM_UNKNOWN_USER_115",
2473 "EM_UNKNOWN_USER_116",
2474 "EM_UNKNOWN_USER_117",
2475 "EM_UNKNOWN_USER_118",
2476 "EM_UNKNOWN_USER_119",
2477 "EM_SETLANGOPTIONS",
2478 "EM_GETLANGOPTIONS",
2479 "EM_GETIMECOMPMODE",
2483 "EM_SETIMEMODEBIAS",
2488 get_msg_name(UINT msg
)
2490 if (msg
>= EM_GETSEL
&& msg
<= EM_CHARFROMPOS
)
2491 return edit_messages
[msg
- EM_GETSEL
];
2492 if (msg
>= EM_CANPASTE
&& msg
<= EM_GETIMEMODEBIAS
)
2493 return richedit_messages
[msg
- EM_CANPASTE
];
2497 static LRESULT
RichEditWndProc_common(HWND hWnd
, UINT msg
, WPARAM wParam
,
2498 LPARAM lParam
, BOOL unicode
)
2500 ME_TextEditor
*editor
= (ME_TextEditor
*)GetWindowLongPtrW(hWnd
, 0);
2502 TRACE("hwnd %p msg %04x (%s) %lx %lx, unicode %d\n",
2503 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
, unicode
);
2505 if (!editor
&& msg
!= WM_NCCREATE
&& msg
!= WM_NCDESTROY
) {
2506 ERR("called with invalid hWnd %p - application bug?\n", hWnd
);
2512 UNSUPPORTED_MSG(EM_DISPLAYBAND
)
2513 UNSUPPORTED_MSG(EM_FINDWORDBREAK
)
2514 UNSUPPORTED_MSG(EM_FMTLINES
)
2515 UNSUPPORTED_MSG(EM_FORMATRANGE
)
2516 UNSUPPORTED_MSG(EM_GETBIDIOPTIONS
)
2517 UNSUPPORTED_MSG(EM_GETEDITSTYLE
)
2518 UNSUPPORTED_MSG(EM_GETIMECOMPMODE
)
2519 /* UNSUPPORTED_MSG(EM_GETIMESTATUS) missing in Wine headers */
2520 UNSUPPORTED_MSG(EM_GETLANGOPTIONS
)
2521 /* UNSUPPORTED_MSG(EM_GETOLEINTERFACE) separate stub */
2522 UNSUPPORTED_MSG(EM_GETREDONAME
)
2523 UNSUPPORTED_MSG(EM_GETTEXTMODE
)
2524 UNSUPPORTED_MSG(EM_GETTYPOGRAPHYOPTIONS
)
2525 UNSUPPORTED_MSG(EM_GETUNDONAME
)
2526 UNSUPPORTED_MSG(EM_GETWORDBREAKPROCEX
)
2527 UNSUPPORTED_MSG(EM_PASTESPECIAL
)
2528 UNSUPPORTED_MSG(EM_SELECTIONTYPE
)
2529 UNSUPPORTED_MSG(EM_SETBIDIOPTIONS
)
2530 UNSUPPORTED_MSG(EM_SETEDITSTYLE
)
2531 UNSUPPORTED_MSG(EM_SETFONTSIZE
)
2532 UNSUPPORTED_MSG(EM_SETLANGOPTIONS
)
2533 UNSUPPORTED_MSG(EM_SETPALETTE
)
2534 UNSUPPORTED_MSG(EM_SETTABSTOPS
)
2535 UNSUPPORTED_MSG(EM_SETTYPOGRAPHYOPTIONS
)
2536 UNSUPPORTED_MSG(EM_SETWORDBREAKPROCEX
)
2537 UNSUPPORTED_MSG(WM_STYLECHANGING
)
2538 UNSUPPORTED_MSG(WM_STYLECHANGED
)
2540 /* Messages specific to Richedit controls */
2543 return ME_StreamIn(editor
, wParam
, (EDITSTREAM
*)lParam
, TRUE
);
2545 return ME_StreamOut(editor
, wParam
, (EDITSTREAM
*)lParam
);
2548 UINT code
= DLGC_WANTCHARS
|DLGC_WANTARROWS
;
2549 if(lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
2551 int vk
= (int)((LPMSG
)lParam
)->wParam
;
2552 /* if style says we want return key */
2553 if((vk
== VK_RETURN
) && (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_WANTRETURN
))
2555 code
|= DLGC_WANTMESSAGE
;
2557 /* we always handle ctrl-tab */
2558 if((vk
== VK_TAB
) && (GetKeyState(VK_CONTROL
) & 0x8000))
2560 code
|= DLGC_WANTMESSAGE
;
2567 CREATESTRUCTW
*pcs
= (CREATESTRUCTW
*)lParam
;
2568 TRACE("WM_NCCREATE: style 0x%08x\n", pcs
->style
);
2569 editor
= ME_MakeEditor(hWnd
);
2570 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)editor
);
2573 case EM_EMPTYUNDOBUFFER
:
2574 ME_EmptyUndoStack(editor
);
2578 /* Note: wParam/lParam can be NULL */
2580 PUINT pfrom
= wParam
? (PUINT
)wParam
: &from
;
2581 PUINT pto
= lParam
? (PUINT
)lParam
: &to
;
2582 ME_GetSelection(editor
, (int *)pfrom
, (int *)pto
);
2583 if ((*pfrom
|*pto
) & 0xFFFF0000)
2585 return MAKELONG(*pfrom
,*pto
);
2589 CHARRANGE
*pRange
= (CHARRANGE
*)lParam
;
2590 ME_GetSelection(editor
, &pRange
->cpMin
, &pRange
->cpMax
);
2591 TRACE("EM_EXGETSEL = (%d,%d)\n", pRange
->cpMin
, pRange
->cpMax
);
2594 case EM_SETUNDOLIMIT
:
2596 if ((int)wParam
< 0)
2597 editor
->nUndoLimit
= STACK_SIZE_DEFAULT
;
2599 editor
->nUndoLimit
= min(wParam
, STACK_SIZE_MAX
);
2600 /* Setting a max stack size keeps wine from getting killed
2601 for hogging memory. Windows allocates all this memory at once, so
2602 no program would realistically set a value above our maximum. */
2603 return editor
->nUndoLimit
;
2606 return editor
->pUndoStack
!= NULL
;
2608 return editor
->pRedoStack
!= NULL
;
2609 case WM_UNDO
: /* FIXME: actually not the same */
2611 return ME_Undo(editor
);
2613 return ME_Redo(editor
);
2616 /* these flags are equivalent to the ES_* counterparts */
2617 DWORD mask
= ECO_VERTICAL
| ECO_AUTOHSCROLL
| ECO_AUTOVSCROLL
|
2618 ECO_NOHIDESEL
| ECO_READONLY
| ECO_WANTRETURN
;
2619 DWORD settings
= GetWindowLongW(hWnd
, GWL_STYLE
) & mask
;
2625 /* these flags are equivalent to ES_* counterparts
2626 * ECO_READONLY is already implemented in the code, only requires
2627 * setting the bit to work
2629 DWORD mask
= ECO_VERTICAL
| ECO_AUTOHSCROLL
| ECO_AUTOVSCROLL
|
2630 ECO_NOHIDESEL
| ECO_READONLY
| ECO_WANTRETURN
| ECO_SELECTIONBAR
;
2631 DWORD raw
= GetWindowLongW(hWnd
, GWL_STYLE
);
2632 DWORD settings
= mask
& raw
;
2648 SetWindowLongW(hWnd
, GWL_STYLE
, (raw
& ~mask
) | (settings
& mask
));
2650 if (settings
& ECO_AUTOWORDSELECTION
)
2651 FIXME("ECO_AUTOWORDSELECTION not implemented yet!\n");
2652 if (settings
& ECO_SELECTIONBAR
)
2653 editor
->selofs
= SELECTIONBAR_WIDTH
;
2656 ME_WrapMarkedParagraphs(editor
);
2658 if (settings
& ECO_VERTICAL
)
2659 FIXME("ECO_VERTICAL not implemented yet!\n");
2660 if (settings
& ECO_AUTOHSCROLL
)
2661 FIXME("ECO_AUTOHSCROLL not implemented yet!\n");
2662 if (settings
& ECO_AUTOVSCROLL
)
2663 FIXME("ECO_AUTOVSCROLL not implemented yet!\n");
2664 if (settings
& ECO_NOHIDESEL
)
2665 FIXME("ECO_NOHIDESEL not implemented yet!\n");
2666 if (settings
& ECO_WANTRETURN
)
2667 FIXME("ECO_WANTRETURN not implemented yet!\n");
2673 ME_InvalidateSelection(editor
);
2674 ME_SetSelection(editor
, wParam
, lParam
);
2675 ME_InvalidateSelection(editor
);
2676 HideCaret(editor
->hWnd
);
2677 ME_ShowCaret(editor
);
2678 ME_SendSelChange(editor
);
2681 case EM_SETSCROLLPOS
:
2683 POINT
*point
= (POINT
*)lParam
;
2684 ME_ScrollAbs(editor
, point
->y
);
2687 case EM_AUTOURLDETECT
:
2689 if (wParam
==1 || wParam
==0)
2691 editor
->AutoURLDetect_bEnable
= (BOOL
)wParam
;
2694 return E_INVALIDARG
;
2696 case EM_GETAUTOURLDETECT
:
2698 return editor
->AutoURLDetect_bEnable
;
2703 CHARRANGE range
= *(CHARRANGE
*)lParam
;
2705 TRACE("EM_EXSETSEL (%d,%d)\n", range
.cpMin
, range
.cpMax
);
2707 ME_InvalidateSelection(editor
);
2708 end
= ME_SetSelection(editor
, range
.cpMin
, range
.cpMax
);
2709 ME_InvalidateSelection(editor
);
2710 HideCaret(editor
->hWnd
);
2711 ME_ShowCaret(editor
);
2712 ME_SendSelChange(editor
);
2716 case EM_SHOWSCROLLBAR
:
2718 ShowScrollBar(editor
->hWnd
, wParam
, lParam
);
2724 SETTEXTEX
*pStruct
= (SETTEXTEX
*)wParam
;
2728 int oldModify
= editor
->nModifyStep
;
2730 if (!pStruct
) return 0;
2732 TRACE("EM_SETTEXTEX - %s, flags %d, cp %d\n",
2733 pStruct
->codepage
== 1200 ? debugstr_w((LPCWSTR
)lParam
) : debugstr_a((LPCSTR
)lParam
),
2734 pStruct
->flags
, pStruct
->codepage
);
2736 /* FIXME: make use of pStruct->codepage in the to unicode translation */
2737 wszText
= lParam
? ME_ToUnicode(pStruct
->codepage
== 1200, (void *)lParam
) : NULL
;
2738 len
= wszText
? lstrlenW(wszText
) : 0;
2740 if (pStruct
->flags
& ST_SELECTION
) {
2741 ME_GetSelection(editor
, &from
, &to
);
2742 style
= ME_GetSelectionInsertStyle(editor
);
2743 ME_InternalDeleteText(editor
, from
, to
- from
, FALSE
);
2744 if (pStruct
->codepage
!= 1200 && lParam
&& !strncmp((char *)lParam
, "{\\rtf", 5))
2745 ME_StreamInRTFString(editor
, 1, (char *)lParam
);
2746 else ME_InsertTextFromCursor(editor
, 0, wszText
, len
, style
);
2747 ME_ReleaseStyle(style
);
2749 if (editor
->AutoURLDetect_bEnable
) ME_UpdateSelectionLinkAttribute(editor
);
2752 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
), FALSE
);
2753 if (pStruct
->codepage
!= 1200 && lParam
&& !strncmp((char *)lParam
, "{\\rtf", 5))
2754 ME_StreamInRTFString(editor
, 0, (char *)lParam
);
2755 else ME_InsertTextFromCursor(editor
, 0, wszText
, len
, editor
->pBuffer
->pDefaultStyle
);
2758 if (editor
->AutoURLDetect_bEnable
) ME_UpdateLinkAttribute(editor
, 0, -1);
2760 ME_CommitUndo(editor
);
2761 if (!(pStruct
->flags
& ST_KEEPUNDO
))
2763 editor
->nModifyStep
= oldModify
;
2764 ME_EmptyUndoStack(editor
);
2766 ME_UpdateRepaint(editor
);
2769 case EM_SETBKGNDCOLOR
:
2772 if (editor
->rgbBackColor
!= -1) {
2773 DeleteObject(editor
->hbrBackground
);
2774 lColor
= editor
->rgbBackColor
;
2776 else lColor
= GetSysColor(COLOR_WINDOW
);
2780 editor
->rgbBackColor
= -1;
2781 editor
->hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
2785 editor
->rgbBackColor
= lParam
;
2786 editor
->hbrBackground
= CreateSolidBrush(editor
->rgbBackColor
);
2788 if (editor
->bRedraw
)
2790 InvalidateRect(hWnd
, NULL
, TRUE
);
2796 return editor
->nModifyStep
== 0 ? 0 : -1;
2800 editor
->nModifyStep
= 1;
2802 editor
->nModifyStep
= 0;
2806 case EM_SETREADONLY
:
2808 long nStyle
= GetWindowLongW(hWnd
, GWL_STYLE
);
2810 nStyle
|= ES_READONLY
;
2812 nStyle
&= ~ES_READONLY
;
2813 SetWindowLongW(hWnd
, GWL_STYLE
, nStyle
);
2816 case EM_SETEVENTMASK
:
2818 DWORD nOldMask
= editor
->nEventMask
;
2820 editor
->nEventMask
= lParam
;
2823 case EM_GETEVENTMASK
:
2824 return editor
->nEventMask
;
2825 case EM_SETCHARFORMAT
:
2827 CHARFORMAT2W buf
, *p
;
2828 BOOL bRepaint
= TRUE
;
2829 p
= ME_ToCF2W(&buf
, (CHARFORMAT2W
*)lParam
);
2830 if (p
== NULL
) return 0;
2832 ME_SetDefaultCharFormat(editor
, p
);
2833 else if (wParam
== (SCF_WORD
| SCF_SELECTION
)) {
2834 FIXME("EM_SETCHARFORMAT: word selection not supported\n");
2836 } else if (wParam
== SCF_ALL
) {
2837 if (editor
->mode
& TM_PLAINTEXT
)
2838 ME_SetDefaultCharFormat(editor
, p
);
2840 ME_SetCharFormat(editor
, 0, ME_GetTextLength(editor
), p
);
2841 editor
->nModifyStep
= 1;
2843 } else if (editor
->mode
& TM_PLAINTEXT
) {
2847 ME_GetSelection(editor
, &from
, &to
);
2848 bRepaint
= (from
!= to
);
2849 ME_SetSelectionCharFormat(editor
, p
);
2850 if (from
!= to
) editor
->nModifyStep
= 1;
2852 ME_CommitUndo(editor
);
2854 ME_RewrapRepaint(editor
);
2857 case EM_GETCHARFORMAT
:
2859 CHARFORMAT2W tmp
, *dst
= (CHARFORMAT2W
*)lParam
;
2860 if (dst
->cbSize
!= sizeof(CHARFORMATA
) &&
2861 dst
->cbSize
!= sizeof(CHARFORMATW
) &&
2862 dst
->cbSize
!= sizeof(CHARFORMAT2A
) &&
2863 dst
->cbSize
!= sizeof(CHARFORMAT2W
))
2865 tmp
.cbSize
= sizeof(tmp
);
2867 ME_GetDefaultCharFormat(editor
, &tmp
);
2869 ME_GetSelectionCharFormat(editor
, &tmp
);
2870 ME_CopyToCFAny(dst
, &tmp
);
2873 case EM_SETPARAFORMAT
:
2875 BOOL result
= ME_SetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
2876 ME_RewrapRepaint(editor
);
2877 ME_CommitUndo(editor
);
2880 case EM_GETPARAFORMAT
:
2881 ME_GetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
2882 return ((PARAFORMAT2
*)lParam
)->dwMask
;
2883 case EM_GETFIRSTVISIBLELINE
:
2885 ME_DisplayItem
*p
= editor
->pBuffer
->pFirst
;
2886 int y
= ME_GetYScrollPos(editor
);
2891 p
= ME_FindItemFwd(p
, diStartRowOrParagraphOrEnd
);
2892 if (p
->type
== diTextEnd
)
2894 if (p
->type
== diParagraph
) {
2895 ypara
= p
->member
.para
.pt
.y
;
2898 ystart
= ypara
+ p
->member
.row
.pt
.y
;
2899 yend
= ystart
+ p
->member
.row
.nHeight
;
2907 case EM_HIDESELECTION
:
2909 editor
->bHideSelection
= (wParam
!= 0);
2910 ME_InvalidateSelection(editor
);
2915 ME_ScrollDown(editor
, lParam
* 8); /* FIXME follow the original */
2916 return TRUE
; /* Should return false if a single line richedit control */
2921 ME_GetSelection(editor
, &from
, &to
);
2922 ME_InternalDeleteText(editor
, from
, to
-from
, FALSE
);
2923 ME_CommitUndo(editor
);
2924 ME_UpdateRepaint(editor
);
2931 LPWSTR wszText
= lParam
? ME_ToUnicode(unicode
, (void *)lParam
) : NULL
;
2932 size_t len
= wszText
? lstrlenW(wszText
) : 0;
2933 TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText
));
2935 ME_GetSelection(editor
, &from
, &to
);
2936 style
= ME_GetSelectionInsertStyle(editor
);
2937 ME_InternalDeleteText(editor
, from
, to
-from
, FALSE
);
2938 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, style
);
2939 ME_ReleaseStyle(style
);
2940 /* drop temporary style if line end */
2942 * FIXME question: does abc\n mean: put abc,
2943 * clear temp style, put \n? (would require a change)
2945 if (len
>0 && wszText
[len
-1] == '\n')
2946 ME_ClearTempStyle(editor
);
2947 ME_EndToUnicode(unicode
, wszText
);
2948 ME_CommitUndo(editor
);
2949 if (editor
->AutoURLDetect_bEnable
) ME_UpdateSelectionLinkAttribute(editor
);
2951 ME_EmptyUndoStack(editor
);
2952 ME_UpdateRepaint(editor
);
2955 case EM_SCROLLCARET
:
2957 int top
, bottom
; /* row's edges relative to document top */
2959 ME_DisplayItem
*para
, *row
;
2961 nPos
= ME_GetYScrollPos(editor
);
2962 row
= ME_RowStart(editor
->pCursors
[0].pRun
);
2963 para
= ME_GetParagraph(row
);
2964 top
= para
->member
.para
.pt
.y
+ row
->member
.row
.pt
.y
;
2965 bottom
= top
+ row
->member
.row
.nHeight
;
2967 if (top
< nPos
) /* caret above window */
2968 ME_ScrollAbs(editor
, top
);
2969 else if (nPos
+ editor
->sizeWindow
.cy
< bottom
) /*below*/
2970 ME_ScrollAbs(editor
, bottom
- editor
->sizeWindow
.cy
);
2978 BOOL bRepaint
= LOWORD(lParam
);
2981 wParam
= (WPARAM
)GetStockObject(SYSTEM_FONT
);
2982 GetObjectW((HGDIOBJ
)wParam
, sizeof(LOGFONTW
), &lf
);
2984 ME_CharFormatFromLogFont(hDC
, &lf
, &fmt
);
2985 ReleaseDC(hWnd
, hDC
);
2986 ME_SetCharFormat(editor
, 0, ME_GetTextLength(editor
), &fmt
);
2987 ME_SetDefaultCharFormat(editor
, &fmt
);
2989 ME_CommitUndo(editor
);
2991 ME_RewrapRepaint(editor
);
2996 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
), FALSE
);
2999 TRACE("WM_SETTEXT lParam==%lx\n",lParam
);
3000 if (!unicode
&& !strncmp((char *)lParam
, "{\\rtf", 5))
3002 /* Undocumented: WM_SETTEXT supports RTF text */
3003 ME_StreamInRTFString(editor
, 0, (char *)lParam
);
3007 LPWSTR wszText
= ME_ToUnicode(unicode
, (void *)lParam
);
3008 TRACE("WM_SETTEXT - %s\n", debugstr_w(wszText
)); /* debugstr_w() */
3009 if (lstrlenW(wszText
) > 0)
3013 /* uses default style! */
3014 if (!(GetWindowLongW(hWnd
, GWL_STYLE
) & ES_MULTILINE
))
3019 while (*p
!= '\0' && *p
!= '\r' && *p
!= '\n') p
++;
3022 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, editor
->pBuffer
->pDefaultStyle
);
3024 ME_EndToUnicode(unicode
, wszText
);
3028 TRACE("WM_SETTEXT - NULL\n");
3029 if (editor
->AutoURLDetect_bEnable
)
3031 ME_UpdateLinkAttribute(editor
, 0, -1);
3033 ME_SetSelection(editor
, 0, 0);
3034 editor
->nModifyStep
= 0;
3035 ME_CommitUndo(editor
);
3036 ME_EmptyUndoStack(editor
);
3037 ME_UpdateRepaint(editor
);
3042 UINT nRTFFormat
= RegisterClipboardFormatA("Rich Text Format");
3043 if (IsClipboardFormatAvailable(nRTFFormat
))
3045 if (IsClipboardFormatAvailable(CF_UNICODETEXT
))
3053 ME_GlobalDestStruct gds
;
3054 UINT nRTFFormat
= RegisterClipboardFormatA("Rich Text Format");
3057 if (IsClipboardFormatAvailable(nRTFFormat
))
3058 cf
= nRTFFormat
, dwFormat
= SF_RTF
;
3059 else if (IsClipboardFormatAvailable(CF_UNICODETEXT
))
3060 cf
= CF_UNICODETEXT
, dwFormat
= SF_TEXT
|SF_UNICODE
;
3064 if (!OpenClipboard(hWnd
))
3066 gds
.hData
= GetClipboardData(cf
);
3068 es
.dwCookie
= (DWORD
)&gds
;
3069 es
.pfnCallback
= dwFormat
== SF_RTF
? ME_ReadFromHGLOBALRTF
: ME_ReadFromHGLOBALUnicode
;
3070 ME_StreamIn(editor
, dwFormat
|SFF_SELECTION
, &es
, FALSE
);
3078 LPDATAOBJECT dataObj
= NULL
;
3082 if (editor
->cPasswordMask
)
3083 return 0; /* Copying or Cutting masked text isn't allowed */
3085 ME_GetSelection(editor
, &range
.cpMin
, &range
.cpMax
);
3086 if(editor
->lpOleCallback
)
3087 hr
= IRichEditOleCallback_GetClipboardData(editor
->lpOleCallback
, &range
, RECO_COPY
, &dataObj
);
3088 if(FAILED(hr
) || !dataObj
)
3089 hr
= ME_GetDataObject(editor
, &range
, &dataObj
);
3091 hr
= OleSetClipboard(dataObj
);
3092 IDataObject_Release(dataObj
);
3094 if (SUCCEEDED(hr
) && msg
== WM_CUT
)
3096 ME_InternalDeleteText(editor
, range
.cpMin
, range
.cpMax
-range
.cpMin
, FALSE
);
3097 ME_CommitUndo(editor
);
3098 ME_UpdateRepaint(editor
);
3102 case WM_GETTEXTLENGTH
:
3104 GETTEXTLENGTHEX how
;
3106 /* CR/LF conversion required in 2.0 mode, verbatim in 1.0 mode */
3107 how
.flags
= GTL_CLOSE
| (editor
->bEmulateVersion10
? 0 : GTL_USECRLF
) | GTL_NUMCHARS
;
3108 how
.codepage
= unicode
? 1200 : CP_ACP
;
3109 return ME_GetTextLengthEx(editor
, &how
);
3111 case EM_GETTEXTLENGTHEX
:
3112 return ME_GetTextLengthEx(editor
, (GETTEXTLENGTHEX
*)wParam
);
3117 LPSTR bufferA
= NULL
;
3118 LPWSTR bufferW
= NULL
;
3121 bufferW
= heap_alloc((wParam
+ 2) * sizeof(WCHAR
));
3123 bufferA
= heap_alloc(wParam
+ 2);
3125 ex
.cb
= (wParam
+ 2) * (unicode
? sizeof(WCHAR
) : sizeof(CHAR
));
3126 ex
.flags
= GT_USECRLF
;
3127 ex
.codepage
= unicode
? 1200 : CP_ACP
;
3128 ex
.lpDefaultChar
= NULL
;
3129 ex
.lpUsedDefChar
= NULL
;
3130 rc
= RichEditWndProc_common(hWnd
, EM_GETTEXTEX
, (WPARAM
)&ex
, unicode
? (LPARAM
)bufferW
: (LPARAM
)bufferA
, unicode
);
3134 memcpy((LPWSTR
)lParam
, bufferW
, wParam
* sizeof(WCHAR
));
3135 if (lstrlenW(bufferW
) >= wParam
) rc
= 0;
3139 memcpy((LPSTR
)lParam
, bufferA
, wParam
);
3140 if (strlen(bufferA
) >= wParam
) rc
= 0;
3148 GETTEXTEX
*ex
= (GETTEXTEX
*)wParam
;
3149 int nStart
, nCount
; /* in chars */
3151 if (ex
->flags
& ~(GT_SELECTION
| GT_USECRLF
))
3152 FIXME("GETTEXTEX flags 0x%08x not supported\n", ex
->flags
& ~(GT_SELECTION
| GT_USECRLF
));
3154 if (ex
->flags
& GT_SELECTION
)
3156 ME_GetSelection(editor
, &nStart
, &nCount
);
3162 nCount
= 0x7fffffff;
3164 if (ex
->codepage
== 1200)
3166 nCount
= min(nCount
, ex
->cb
/ sizeof(WCHAR
) - 1);
3167 return ME_GetTextW(editor
, (LPWSTR
)lParam
, nStart
, nCount
, ex
->flags
& GT_USECRLF
);
3171 /* potentially each char may be a CR, why calculate the exact value with O(N) when
3172 we can just take a bigger buffer? :)
3173 The above assumption still holds with CR/LF counters, since CR->CRLF expansion
3174 occurs only in richedit 2.0 mode, in which line breaks have only one CR
3176 int crlfmul
= (ex
->flags
& GT_USECRLF
) ? 2 : 1;
3178 DWORD buflen
= ex
->cb
;
3182 nCount
= min(nCount
, ex
->cb
- 1);
3183 buffer
= heap_alloc((crlfmul
*nCount
+ 1) * sizeof(WCHAR
));
3185 buflen
= ME_GetTextW(editor
, buffer
, nStart
, nCount
, ex
->flags
& GT_USECRLF
);
3186 rc
= WideCharToMultiByte(ex
->codepage
, flags
, buffer
, buflen
+1, (LPSTR
)lParam
, ex
->cb
, ex
->lpDefaultChar
, ex
->lpUsedDefChar
);
3187 if (rc
) rc
--; /* do not count 0 terminator */
3196 TEXTRANGEW tr
; /* W and A differ only by rng->lpstrText */
3197 ME_GetSelection(editor
, &from
, &to
);
3198 tr
.chrg
.cpMin
= from
;
3200 tr
.lpstrText
= (WCHAR
*)lParam
;
3201 return RichEditWndProc_common(hWnd
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
, unicode
);
3203 case EM_GETSCROLLPOS
:
3205 POINT
*point
= (POINT
*)lParam
;
3206 point
->x
= 0; /* FIXME side scrolling not implemented */
3207 point
->y
= ME_GetYScrollPos(editor
);
3210 case EM_GETTEXTRANGE
:
3212 TEXTRANGEW
*rng
= (TEXTRANGEW
*)lParam
;
3213 TRACE("EM_GETTEXTRANGE min=%d max=%d unicode=%d emul1.0=%d length=%d\n",
3214 rng
->chrg
.cpMin
, rng
->chrg
.cpMax
, unicode
,
3215 editor
->bEmulateVersion10
, ME_GetTextLength(editor
));
3217 return ME_GetTextW(editor
, rng
->lpstrText
, rng
->chrg
.cpMin
, rng
->chrg
.cpMax
-rng
->chrg
.cpMin
, 0);
3220 int nLen
= rng
->chrg
.cpMax
-rng
->chrg
.cpMin
;
3221 WCHAR
*p
= ALLOC_N_OBJ(WCHAR
, nLen
+1);
3222 int nChars
= ME_GetTextW(editor
, p
, rng
->chrg
.cpMin
, nLen
, 0);
3223 /* FIXME this is a potential security hole (buffer overrun)
3224 if you know more about wchar->mbyte conversion please explain
3226 WideCharToMultiByte(CP_ACP
, 0, p
, nChars
+1, (char *)rng
->lpstrText
, nLen
+1, NULL
, NULL
);
3233 ME_DisplayItem
*run
;
3234 const unsigned int nMaxChars
= *(WORD
*) lParam
;
3235 unsigned int nCharsLeft
= nMaxChars
;
3236 char *dest
= (char *) lParam
;
3237 BOOL wroteNull
= FALSE
;
3239 TRACE("EM_GETLINE: row=%d, nMaxChars=%d (%s)\n", (int) wParam
, nMaxChars
,
3240 unicode
? "Unicode" : "Ansi");
3242 run
= ME_FindRowWithNumber(editor
, wParam
);
3246 while (nCharsLeft
&& (run
= ME_FindItemFwd(run
, diRunOrStartRow
))
3247 && !(run
->member
.run
.nFlags
& MERF_ENDPARA
))
3251 if (run
->type
!= diRun
)
3253 strText
= run
->member
.run
.strText
;
3254 nCopy
= min(nCharsLeft
, strText
->nLen
);
3257 lstrcpynW((LPWSTR
) dest
, strText
->szData
, nCopy
);
3259 nCopy
= WideCharToMultiByte(CP_ACP
, 0, strText
->szData
, nCopy
, dest
,
3260 nCharsLeft
, NULL
, NULL
);
3261 dest
+= nCopy
* (unicode
? sizeof(WCHAR
) : 1);
3262 nCharsLeft
-= nCopy
;
3265 /* append line termination, space allowing */
3268 if (run
&& (run
->member
.run
.nFlags
& MERF_ENDPARA
))
3271 /* Write as many \r as encoded in end-of-paragraph, space allowing */
3272 for (i
= 0; i
< run
->member
.run
.nCR
&& nCharsLeft
> 0; i
++, nCharsLeft
--)
3274 *((WCHAR
*)dest
) = '\r';
3275 dest
+= unicode
? sizeof(WCHAR
) : 1;
3277 /* Write as many \n as encoded in end-of-paragraph, space allowing */
3278 for (i
= 0; i
< run
->member
.run
.nLF
&& nCharsLeft
> 0; i
++, nCharsLeft
--)
3280 *((WCHAR
*)dest
) = '\n';
3281 dest
+= unicode
? sizeof(WCHAR
) : 1;
3287 *((WCHAR
*)dest
) = '\0';
3295 TRACE("EM_GETLINE: got %u characters\n", nMaxChars
- nCharsLeft
);
3296 return nMaxChars
- nCharsLeft
- (wroteNull
? 1 : 0);
3298 case EM_GETLINECOUNT
:
3300 ME_DisplayItem
*item
= editor
->pBuffer
->pFirst
->next
;
3303 ME_DisplayItem
*prev_para
= NULL
, *last_para
= NULL
;
3305 while (item
!= editor
->pBuffer
->pLast
)
3307 assert(item
->type
== diParagraph
);
3308 prev_para
= ME_FindItemBack(item
, diRun
);
3310 assert(prev_para
->member
.run
.nFlags
& MERF_ENDPARA
);
3312 nRows
+= item
->member
.para
.nRows
;
3313 item
= item
->member
.para
.next_para
;
3315 last_para
= ME_FindItemBack(item
, diRun
);
3317 assert(last_para
->member
.run
.nFlags
& MERF_ENDPARA
);
3318 if (editor
->bEmulateVersion10
&& prev_para
&& last_para
->member
.run
.nCharOfs
== 0
3319 && prev_para
->member
.run
.nCR
== 1 && prev_para
->member
.run
.nLF
== 0)
3321 /* In 1.0 emulation, the last solitary \r at the very end of the text
3322 (if one exists) is NOT a line break.
3323 FIXME: this is an ugly hack. This should have a more regular model. */
3327 TRACE("EM_GETLINECOUNT: nRows==%d\n", nRows
);
3328 return max(1, nRows
);
3330 case EM_LINEFROMCHAR
:
3333 return ME_RowNumberFromCharOfs(editor
, ME_GetCursorOfs(editor
, 1));
3335 return ME_RowNumberFromCharOfs(editor
, wParam
);
3337 case EM_EXLINEFROMCHAR
:
3340 return ME_RowNumberFromCharOfs(editor
, ME_GetCursorOfs(editor
,1));
3342 return ME_RowNumberFromCharOfs(editor
, lParam
);
3346 ME_DisplayItem
*item
, *para
;
3350 item
= ME_FindItemBack(editor
->pCursors
[0].pRun
, diStartRow
);
3352 item
= ME_FindRowWithNumber(editor
, wParam
);
3355 para
= ME_GetParagraph(item
);
3356 item
= ME_FindItemFwd(item
, diRun
);
3357 nCharOfs
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
;
3358 TRACE("EM_LINEINDEX: nCharOfs==%d\n", nCharOfs
);
3363 ME_DisplayItem
*item
, *item_end
;
3364 int nChars
= 0, nThisLineOfs
= 0, nNextLineOfs
= 0;
3366 if (wParam
> ME_GetTextLength(editor
))
3370 FIXME("EM_LINELENGTH: returning number of unselected characters on lines with selection unsupported.\n");
3373 item
= ME_FindItemAtOffset(editor
, diRun
, wParam
, NULL
);
3374 item
= ME_RowStart(item
);
3375 nThisLineOfs
= ME_CharOfsFromRunOfs(editor
, ME_FindItemFwd(item
, diRun
), 0);
3376 item_end
= ME_FindItemFwd(item
, diStartRowOrParagraphOrEnd
);
3377 if (item_end
->type
== diStartRow
)
3378 nNextLineOfs
= ME_CharOfsFromRunOfs(editor
, ME_FindItemFwd(item_end
, diRun
), 0);
3381 ME_DisplayItem
*endPara
;
3383 nNextLineOfs
= ME_FindItemFwd(item
, diParagraphOrEnd
)->member
.para
.nCharOfs
;
3384 endPara
= ME_FindItemFwd(item
, diParagraphOrEnd
);
3385 endPara
= ME_FindItemBack(endPara
, diRun
);
3387 assert(endPara
->type
== diRun
);
3388 assert(endPara
->member
.run
.nFlags
& MERF_ENDPARA
);
3389 nNextLineOfs
-= endPara
->member
.run
.nCR
+ endPara
->member
.run
.nLF
;
3391 nChars
= nNextLineOfs
- nThisLineOfs
;
3392 TRACE("EM_LINELENGTH(%ld)==%d\n",wParam
, nChars
);
3395 case EM_EXLIMITTEXT
:
3397 if ((int)lParam
< 0)
3400 editor
->nTextLimit
= 65536;
3402 editor
->nTextLimit
= (int) lParam
;
3408 editor
->nTextLimit
= 65536;
3410 editor
->nTextLimit
= (int) wParam
;
3413 case EM_GETLIMITTEXT
:
3415 return editor
->nTextLimit
;
3419 FINDTEXTA
*ft
= (FINDTEXTA
*)lParam
;
3420 int nChars
= MultiByteToWideChar(CP_ACP
, 0, ft
->lpstrText
, -1, NULL
, 0);
3424 if ((tmp
= ALLOC_N_OBJ(WCHAR
, nChars
)) != NULL
)
3425 MultiByteToWideChar(CP_ACP
, 0, ft
->lpstrText
, -1, tmp
, nChars
);
3426 r
= ME_FindText(editor
, wParam
, &ft
->chrg
, tmp
, NULL
);
3432 FINDTEXTEXA
*ex
= (FINDTEXTEXA
*)lParam
;
3433 int nChars
= MultiByteToWideChar(CP_ACP
, 0, ex
->lpstrText
, -1, NULL
, 0);
3437 if ((tmp
= ALLOC_N_OBJ(WCHAR
, nChars
)) != NULL
)
3438 MultiByteToWideChar(CP_ACP
, 0, ex
->lpstrText
, -1, tmp
, nChars
);
3439 r
= ME_FindText(editor
, wParam
, &ex
->chrg
, tmp
, &ex
->chrgText
);
3445 FINDTEXTW
*ft
= (FINDTEXTW
*)lParam
;
3446 return ME_FindText(editor
, wParam
, &ft
->chrg
, ft
->lpstrText
, NULL
);
3448 case EM_FINDTEXTEXW
:
3450 FINDTEXTEXW
*ex
= (FINDTEXTEXW
*)lParam
;
3451 return ME_FindText(editor
, wParam
, &ex
->chrg
, ex
->lpstrText
, &ex
->chrgText
);
3454 if (!wParam
|| !lParam
)
3456 *(int *)wParam
= editor
->nZoomNumerator
;
3457 *(int *)lParam
= editor
->nZoomDenominator
;
3460 return ME_SetZoom(editor
, wParam
, lParam
);
3461 case EM_CHARFROMPOS
:
3462 return ME_CharFromPos(editor
, ((POINTL
*)lParam
)->x
, ((POINTL
*)lParam
)->y
, NULL
);
3463 case EM_POSFROMCHAR
:
3465 ME_DisplayItem
*pRun
;
3466 int nCharOfs
, nOffset
, nLength
;
3471 /* detect which API version we're dealing with */
3472 if (wParam
>= 0x40000)
3474 nLength
= ME_GetTextLength(editor
);
3476 if (nCharOfs
< nLength
) {
3477 ME_RunOfsFromCharOfs(editor
, nCharOfs
, &pRun
, &nOffset
);
3478 assert(pRun
->type
== diRun
);
3479 pt
.y
= pRun
->member
.run
.pt
.y
;
3480 pt
.x
= pRun
->member
.run
.pt
.x
+ ME_PointFromChar(editor
, &pRun
->member
.run
, nOffset
);
3481 pt
.y
+= ME_GetParagraph(pRun
)->member
.para
.pt
.y
;
3484 pt
.y
= editor
->pBuffer
->pLast
->member
.para
.pt
.y
;
3486 pt
.x
+= editor
->selofs
;
3488 si
.cbSize
= sizeof(si
);
3490 if (GetScrollInfo(editor
->hWnd
, SB_VERT
, &si
)) pt
.y
-= si
.nPos
;
3491 si
.cbSize
= sizeof(si
);
3493 if (GetScrollInfo(editor
->hWnd
, SB_HORZ
, &si
)) pt
.x
-= si
.nPos
;
3495 if (wParam
>= 0x40000) {
3496 *(POINTL
*)wParam
= pt
;
3498 return (wParam
>= 0x40000) ? 0 : MAKELONG( pt
.x
, pt
.y
);
3504 GetClientRect(hWnd
, &editor
->rcFormat
);
3505 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_HSCROLL
)
3506 { /* Squelch the default horizontal scrollbar it would make */
3507 ShowScrollBar(editor
->hWnd
, SB_HORZ
, FALSE
);
3510 si
.cbSize
= sizeof(si
);
3511 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
3512 if (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_DISABLENOSCROLL
)
3513 si
.fMask
|= SIF_DISABLENOSCROLL
;
3514 si
.nMax
= (si
.fMask
& SIF_DISABLENOSCROLL
) ? 1 : 0;
3517 SetScrollInfo(hWnd
, SB_VERT
, &si
, TRUE
);
3519 ME_CommitUndo(editor
);
3520 ME_WrapMarkedParagraphs(editor
);
3521 ME_MoveCaret(editor
);
3525 ME_DestroyEditor(editor
);
3526 SetWindowLongPtrW(hWnd
, 0, 0);
3530 return ME_SetCursor(editor
);
3532 case WM_LBUTTONDBLCLK
:
3533 case WM_LBUTTONDOWN
:
3535 ME_CommitUndo(editor
); /* End coalesced undos for typed characters */
3536 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
3537 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3540 ME_LButtonDown(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
),
3541 ME_CalculateClickCount(hWnd
, msg
, wParam
, lParam
));
3543 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
3544 if (!ME_SetCursor(editor
)) goto do_default
;
3548 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
3549 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3551 if (GetCapture() == hWnd
)
3552 ME_MouseMove(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
3553 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
3554 /* Set cursor if mouse is captured, since WM_SETCURSOR won't be received. */
3555 if (GetCapture() == hWnd
)
3556 ME_SetCursor(editor
);
3559 if (GetCapture() == hWnd
)
3561 if (editor
->nSelectionType
== stDocument
)
3562 editor
->nSelectionType
= stPosition
;
3563 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
3564 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3568 ME_SetCursor(editor
);
3569 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
3573 case WM_RBUTTONDOWN
:
3574 ME_CommitUndo(editor
); /* End coalesced undos for typed characters */
3575 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
3576 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3579 case WM_CONTEXTMENU
:
3580 if (!ME_ShowContextMenu(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
)))
3584 if (editor
->bRedraw
)
3589 hDC
= BeginPaint(hWnd
, &ps
);
3590 ME_PaintContent(editor
, hDC
, FALSE
, &ps
.rcPaint
);
3591 EndPaint(hWnd
, &ps
);
3595 editor
->bHaveFocus
= TRUE
;
3596 ME_ShowCaret(editor
);
3597 ME_SendOldNotify(editor
, EN_SETFOCUS
);
3600 ME_CommitUndo(editor
); /* End coalesced undos for typed characters */
3601 editor
->bHaveFocus
= FALSE
;
3602 ME_HideCaret(editor
);
3603 ME_SendOldNotify(editor
, EN_KILLFOCUS
);
3607 if (editor
->bRedraw
)
3609 HDC hDC
= (HDC
)wParam
;
3611 if (GetUpdateRect(hWnd
,&rc
,TRUE
))
3613 FillRect(hDC
, &rc
, editor
->hbrBackground
);
3619 TRACE("editor wnd command = %d\n", LOWORD(wParam
));
3622 if ((editor
->nEventMask
& ENM_KEYEVENTS
) &&
3623 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3627 if ((editor
->nEventMask
& ENM_KEYEVENTS
) &&
3628 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3630 if (ME_KeyDown(editor
, LOWORD(wParam
)))
3638 wstr
= (WCHAR
)wParam
;
3641 CHAR charA
= wParam
;
3642 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &wstr
, 1);
3647 case 1: /* Ctrl-A */
3648 ME_SetSelection(editor
, 0, -1);
3650 case 3: /* Ctrl-C */
3651 SendMessageW(editor
->hWnd
, WM_COPY
, 0, 0);
3655 if (GetWindowLongW(editor
->hWnd
, GWL_STYLE
) & ES_READONLY
) {
3656 MessageBeep(MB_ICONERROR
);
3657 return 0; /* FIXME really 0 ? */
3662 case 22: /* Ctrl-V */
3663 SendMessageW(editor
->hWnd
, WM_PASTE
, 0, 0);
3665 case 24: /* Ctrl-X */
3666 SendMessageW(editor
->hWnd
, WM_CUT
, 0, 0);
3668 case 25: /* Ctrl-Y */
3669 SendMessageW(editor
->hWnd
, EM_REDO
, 0, 0);
3671 case 26: /* Ctrl-Z */
3672 SendMessageW(editor
->hWnd
, EM_UNDO
, 0, 0);
3675 if (((unsigned)wstr
)>=' '
3676 || (wstr
=='\r' && (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_MULTILINE
))
3678 ME_Cursor cursor
= editor
->pCursors
[0];
3679 ME_DisplayItem
*para
= ME_GetParagraph(cursor
.pRun
);
3681 BOOL ctrl_is_down
= GetKeyState(VK_CONTROL
) & 0x8000;
3682 ME_GetSelection(editor
, &from
, &to
);
3684 /* v4.1 allows tabs to be inserted with ctrl key down */
3685 && !(ctrl_is_down
&& !editor
->bEmulateVersion10
)
3688 ME_DisplayItem
*para
;
3689 BOOL bSelectedRow
= FALSE
;
3691 para
= ME_GetParagraph(cursor
.pRun
);
3692 if (ME_IsSelection(editor
) &&
3693 cursor
.pRun
->member
.run
.nCharOfs
+ cursor
.nOffset
== 0 &&
3694 to
== ME_GetCursorOfs(editor
, 0) &&
3695 para
->member
.para
.prev_para
->type
== diParagraph
)
3697 para
= para
->member
.para
.prev_para
;
3698 bSelectedRow
= TRUE
;
3700 if (ME_IsInTable(para
))
3702 ME_TabPressedInTable(editor
, bSelectedRow
);
3703 ME_CommitUndo(editor
);
3706 } else if (!editor
->bEmulateVersion10
) { /* v4.1 */
3707 if (para
->member
.para
.nFlags
& MEPF_ROWEND
) {
3709 /* Add a new table row after this row. */
3710 para
= ME_AppendTableRow(editor
, para
);
3711 para
= para
->member
.para
.next_para
;
3712 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
3713 editor
->pCursors
[0].nOffset
= 0;
3714 editor
->pCursors
[1] = editor
->pCursors
[0];
3715 ME_CommitUndo(editor
);
3716 ME_CheckTablesForCorruption(editor
);
3717 ME_UpdateRepaint(editor
);
3719 } else if (from
== to
) {
3720 para
= para
->member
.para
.next_para
;
3721 if (para
->member
.para
.nFlags
& MEPF_ROWSTART
)
3722 para
= para
->member
.para
.next_para
;
3723 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
3724 editor
->pCursors
[0].nOffset
= 0;
3725 editor
->pCursors
[1] = editor
->pCursors
[0];
3728 else if (para
== ME_GetParagraph(editor
->pCursors
[1].pRun
) &&
3729 cursor
.nOffset
+ cursor
.pRun
->member
.run
.nCharOfs
== 0 &&
3730 para
->member
.para
.prev_para
->member
.para
.nFlags
& MEPF_ROWSTART
&&
3731 !para
->member
.para
.prev_para
->member
.para
.nCharOfs
)
3733 /* Insert a newline before the table. */
3735 para
= para
->member
.para
.prev_para
;
3736 para
->member
.para
.nFlags
&= ~MEPF_ROWSTART
;
3737 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
3738 editor
->pCursors
[1] = editor
->pCursors
[0];
3739 ME_InsertTextFromCursor(editor
, 0, &endl
, 1,
3740 editor
->pCursors
[0].pRun
->member
.run
.style
);
3741 para
= editor
->pBuffer
->pFirst
->member
.para
.next_para
;
3742 ME_SetDefaultParaFormat(para
->member
.para
.pFmt
);
3743 para
->member
.para
.nFlags
= MEPF_REWRAP
;
3744 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
3745 editor
->pCursors
[1] = editor
->pCursors
[0];
3746 para
->member
.para
.next_para
->member
.para
.nFlags
|= MEPF_ROWSTART
;
3747 ME_CommitCoalescingUndo(editor
);
3748 ME_CheckTablesForCorruption(editor
);
3749 ME_UpdateRepaint(editor
);
3752 } else { /* v1.0 - 3.0 */
3753 ME_DisplayItem
*para
= ME_GetParagraph(cursor
.pRun
);
3754 if (ME_IsInTable(cursor
.pRun
))
3756 if (cursor
.pRun
->member
.run
.nFlags
& MERF_ENDPARA
)
3760 ME_ContinueCoalescingTransaction(editor
);
3761 para
= ME_AppendTableRow(editor
, para
);
3762 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
3763 editor
->pCursors
[0].nOffset
= 0;
3764 editor
->pCursors
[1] = editor
->pCursors
[0];
3765 ME_CommitCoalescingUndo(editor
);
3766 ME_UpdateRepaint(editor
);
3768 /* Text should not be inserted at the end of the table. */
3773 } else if (wstr
== '\r') {
3774 ME_ContinueCoalescingTransaction(editor
);
3775 if (cursor
.pRun
->member
.run
.nCharOfs
+ cursor
.nOffset
== 0 &&
3776 !ME_IsInTable(para
->member
.para
.prev_para
))
3778 /* Insert newline before table */
3780 cursor
.pRun
= ME_FindItemBack(para
, diRun
);
3782 editor
->pCursors
[0].pRun
= cursor
.pRun
;
3783 editor
->pCursors
[0].nOffset
= 0;
3784 editor
->pCursors
[1] = editor
->pCursors
[0];
3785 ME_InsertTextFromCursor(editor
, 0, &endl
, 1,
3786 editor
->pCursors
[0].pRun
->member
.run
.style
);
3788 editor
->pCursors
[1] = editor
->pCursors
[0];
3789 para
= ME_AppendTableRow(editor
, para
);
3790 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
3791 editor
->pCursors
[0].nOffset
= 0;
3792 editor
->pCursors
[1] = editor
->pCursors
[0];
3794 ME_CommitCoalescingUndo(editor
);
3795 ME_UpdateRepaint(editor
);
3800 /* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */
3801 /* WM_CHAR is restricted to nTextLimit */
3802 if(editor
->nTextLimit
> ME_GetTextLength(editor
) - (to
-from
))
3804 ME_Style
*style
= ME_GetInsertStyle(editor
, 0);
3805 ME_SaveTempStyle(editor
);
3806 ME_ContinueCoalescingTransaction(editor
);
3807 if (wstr
== '\r' && (GetKeyState(VK_SHIFT
) & 0x8000))
3808 ME_InsertEndRowFromCursor(editor
, 0);
3810 ME_InsertTextFromCursor(editor
, 0, &wstr
, 1, style
);
3811 ME_ReleaseStyle(style
);
3812 ME_CommitCoalescingUndo(editor
);
3816 if (editor
->AutoURLDetect_bEnable
) ME_UpdateSelectionLinkAttribute(editor
);
3818 ME_UpdateRepaint(editor
);
3825 if(wParam
== UNICODE_NOCHAR
) return TRUE
;
3826 if(wParam
<= 0x000fffff)
3828 if(wParam
> 0xffff) /* convert to surrogates */
3831 SendMessageW(editor
->hWnd
, WM_CHAR
, (wParam
>> 10) + 0xd800, 0);
3832 SendMessageW(editor
->hWnd
, WM_CHAR
, (wParam
& 0x03ff) + 0xdc00, 0);
3834 else SendMessageW(editor
->hWnd
, WM_CHAR
, wParam
, 0);
3839 case EM_STOPGROUPTYPING
:
3840 ME_CommitUndo(editor
); /* End coalesced undos for typed characters */
3842 case EM_SCROLL
: /* fall through */
3848 origNPos
= ME_GetYScrollPos(editor
);
3851 if (editor
&& editor
->pBuffer
&& editor
->pBuffer
->pDefaultStyle
)
3852 lineHeight
= editor
->pBuffer
->pDefaultStyle
->tm
.tmHeight
;
3853 if (lineHeight
<= 0) lineHeight
= 24;
3855 switch(LOWORD(wParam
))
3858 ME_ScrollUp(editor
,lineHeight
);
3861 ME_ScrollDown(editor
,lineHeight
);
3864 ME_ScrollUp(editor
,editor
->sizeWindow
.cy
);
3867 ME_ScrollDown(editor
,editor
->sizeWindow
.cy
);
3870 case SB_THUMBPOSITION
:
3871 ME_ScrollAbs(editor
,HIWORD(wParam
));
3874 if (msg
== EM_SCROLL
)
3875 return 0x00010000 | (((ME_GetYScrollPos(editor
) - origNPos
)/lineHeight
) & 0xffff);
3881 UINT pulScrollLines
;
3883 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
3884 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3887 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
3888 gcWheelDelta
= -GET_WHEEL_DELTA_WPARAM(wParam
);
3890 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
3892 /* FIXME follow the original */
3893 ME_ScrollDown(editor
,pulScrollLines
* (gcWheelDelta
/ WHEEL_DELTA
) * 8);
3899 *((RECT
*)lParam
) = editor
->rcFormat
;
3907 RECT
*rc
= (RECT
*)lParam
;
3911 editor
->rcFormat
.left
+= rc
->left
;
3912 editor
->rcFormat
.top
+= rc
->top
;
3913 editor
->rcFormat
.right
+= rc
->right
;
3914 editor
->rcFormat
.bottom
+= rc
->bottom
;
3918 editor
->rcFormat
= *rc
;
3923 GetClientRect(hWnd
, &editor
->rcFormat
);
3925 if (msg
!= EM_SETRECTNP
)
3926 ME_RewrapRepaint(editor
);
3929 case EM_REQUESTRESIZE
:
3930 ME_SendRequestResize(editor
, TRUE
);
3933 if ((editor
->bRedraw
= wParam
))
3934 ME_RewrapRepaint(editor
);
3938 GetClientRect(hWnd
, &editor
->rcFormat
);
3939 ME_RewrapRepaint(editor
);
3940 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
3942 /* IME messages to make richedit controls IME aware */
3943 case WM_IME_SETCONTEXT
:
3944 case WM_IME_CONTROL
:
3946 case WM_IME_COMPOSITIONFULL
:
3948 case WM_IME_STARTCOMPOSITION
:
3950 editor
->imeStartIndex
=ME_GetCursorOfs(editor
,0);
3951 ME_DeleteSelection(editor
);
3952 ME_CommitUndo(editor
);
3953 ME_UpdateRepaint(editor
);
3956 case WM_IME_COMPOSITION
:
3960 ME_Style
*style
= ME_GetInsertStyle(editor
, 0);
3961 hIMC
= ImmGetContext(hWnd
);
3962 ME_DeleteSelection(editor
);
3963 ME_CommitUndo(editor
);
3964 ME_SaveTempStyle(editor
);
3965 if (lParam
& GCS_RESULTSTR
)
3967 LPWSTR lpCompStr
= NULL
;
3970 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
3971 lpCompStr
= HeapAlloc(GetProcessHeap(),0,dwBufLen
+ sizeof(WCHAR
));
3972 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpCompStr
, dwBufLen
);
3973 lpCompStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
3974 ME_InsertTextFromCursor(editor
,0,lpCompStr
,dwBufLen
/sizeof(WCHAR
),style
);
3976 else if (lParam
& GCS_COMPSTR
)
3978 LPWSTR lpCompStr
= NULL
;
3981 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
3982 lpCompStr
= HeapAlloc(GetProcessHeap(),0,dwBufLen
+ sizeof(WCHAR
));
3983 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, dwBufLen
);
3984 lpCompStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
3986 ME_InsertTextFromCursor(editor
,0,lpCompStr
,dwBufLen
/sizeof(WCHAR
),style
);
3987 ME_SetSelection(editor
,editor
->imeStartIndex
,
3988 editor
->imeStartIndex
+ dwBufLen
/sizeof(WCHAR
));
3990 ME_ReleaseStyle(style
);
3991 ME_UpdateRepaint(editor
);
3994 case WM_IME_ENDCOMPOSITION
:
3996 ME_DeleteSelection(editor
);
3997 editor
->imeStartIndex
=-1;
4000 case EM_GETOLEINTERFACE
:
4002 LPVOID
*ppvObj
= (LPVOID
*) lParam
;
4003 return CreateIRichEditOle(editor
, ppvObj
);
4005 case EM_GETPASSWORDCHAR
:
4007 return editor
->cPasswordMask
;
4009 case EM_SETOLECALLBACK
:
4010 if(editor
->lpOleCallback
)
4011 IUnknown_Release(editor
->lpOleCallback
);
4012 editor
->lpOleCallback
= (LPRICHEDITOLECALLBACK
)lParam
;
4013 if(editor
->lpOleCallback
)
4014 IUnknown_AddRef(editor
->lpOleCallback
);
4016 case EM_GETWORDBREAKPROC
:
4017 return (LRESULT
)editor
->pfnWordBreak
;
4018 case EM_SETWORDBREAKPROC
:
4020 EDITWORDBREAKPROCW pfnOld
= editor
->pfnWordBreak
;
4022 editor
->pfnWordBreak
= (EDITWORDBREAKPROCW
)lParam
;
4023 return (LRESULT
)pfnOld
;
4025 case EM_SETTEXTMODE
:
4030 ret
= RichEditWndProc_common(hWnd
, WM_GETTEXTLENGTH
, 0, 0, unicode
);
4033 /*Check for valid wParam*/
4034 if ((((wParam
& TM_RICHTEXT
) && ((wParam
& TM_PLAINTEXT
) << 1))) ||
4035 (((wParam
& TM_MULTILEVELUNDO
) && ((wParam
& TM_SINGLELEVELUNDO
) << 1))) ||
4036 (((wParam
& TM_MULTICODEPAGE
) && ((wParam
& TM_SINGLECODEPAGE
) << 1))))
4040 if (wParam
& (TM_RICHTEXT
| TM_PLAINTEXT
))
4042 mask
|= (TM_RICHTEXT
| TM_PLAINTEXT
);
4043 changes
|= (wParam
& (TM_RICHTEXT
| TM_PLAINTEXT
));
4045 /*FIXME: Currently no support for undo level and code page options*/
4046 editor
->mode
= (editor
->mode
& (~mask
)) | changes
;
4052 case EM_SETPASSWORDCHAR
:
4054 editor
->cPasswordMask
= wParam
;
4055 ME_RewrapRepaint(editor
);
4058 case EM_SETTARGETDEVICE
:
4061 BOOL
new = (lParam
== 0);
4062 if (editor
->bWordWrap
!= new)
4064 editor
->bWordWrap
= new;
4065 ME_RewrapRepaint(editor
);
4068 else FIXME("Unsupported yet non NULL device in EM_SETTARGETDEVICE\n");
4072 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
4077 static LRESULT WINAPI
RichEditWndProcW(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4079 BOOL unicode
= TRUE
;
4081 /* Under Win9x RichEdit20W returns ANSI strings, see the tests. */
4082 if (msg
== WM_GETTEXT
&& (GetVersion() & 0x80000000))
4085 return RichEditWndProc_common(hWnd
, msg
, wParam
, lParam
, unicode
);
4088 static LRESULT WINAPI
RichEditWndProcA(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4090 return RichEditWndProc_common(hWnd
, msg
, wParam
, lParam
, FALSE
);
4093 /******************************************************************
4094 * RichEditANSIWndProc (RICHED20.10)
4096 LRESULT WINAPI
RichEditANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4098 return RichEditWndProcA(hWnd
, msg
, wParam
, lParam
);
4101 /******************************************************************
4102 * RichEdit10ANSIWndProc (RICHED20.9)
4104 LRESULT WINAPI
RichEdit10ANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4108 /* FIXME: this is NOT the same as 2.0 version */
4109 result
= RichEditANSIWndProc(hWnd
, msg
, wParam
, lParam
);
4110 if (msg
== WM_NCCREATE
)
4112 ME_TextEditor
*editor
= (ME_TextEditor
*)GetWindowLongPtrW(hWnd
, 0);
4114 editor
->bEmulateVersion10
= TRUE
;
4115 editor
->pBuffer
->pLast
->member
.para
.nCharOfs
= 2;
4116 assert(editor
->pBuffer
->pLast
->prev
->type
== diRun
);
4117 assert(editor
->pBuffer
->pLast
->prev
->member
.run
.nFlags
& MERF_ENDPARA
);
4118 editor
->pBuffer
->pLast
->prev
->member
.run
.nLF
= 1;
4123 void ME_SendOldNotify(ME_TextEditor
*editor
, int nCode
)
4125 HWND hWnd
= editor
->hWnd
;
4126 SendMessageA(GetParent(hWnd
), WM_COMMAND
, (nCode
<<16)|GetWindowLongW(hWnd
, GWLP_ID
), (LPARAM
)hWnd
);
4129 void ME_LinkNotify(ME_TextEditor
*editor
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4132 ME_Cursor tmpCursor
;
4134 int nCharOfs
; /* The start of the clicked text. Absolute character offset */
4139 x
= (short)LOWORD(lParam
);
4140 y
= (short)HIWORD(lParam
);
4141 nCharOfs
= ME_CharFromPos(editor
, x
, y
, &isExact
);
4142 if (!isExact
) return;
4144 ME_CursorFromCharOfs(editor
, nCharOfs
, &tmpCursor
);
4145 tmpRun
= &tmpCursor
.pRun
->member
.run
;
4147 if ((tmpRun
->style
->fmt
.dwMask
& CFM_LINK
)
4148 && (tmpRun
->style
->fmt
.dwEffects
& CFE_LINK
))
4149 { /* The clicked run has CFE_LINK set */
4150 info
.nmhdr
.hwndFrom
= editor
->hWnd
;
4151 info
.nmhdr
.idFrom
= GetWindowLongW(editor
->hWnd
, GWLP_ID
);
4152 info
.nmhdr
.code
= EN_LINK
;
4154 info
.wParam
= wParam
;
4155 info
.lParam
= lParam
;
4156 info
.chrg
.cpMin
= ME_CharOfsFromRunOfs(editor
,tmpCursor
.pRun
,0);
4157 info
.chrg
.cpMax
= info
.chrg
.cpMin
+ ME_StrVLen(tmpRun
->strText
);
4158 SendMessageW(GetParent(editor
->hWnd
), WM_NOTIFY
,info
.nmhdr
.idFrom
, (LPARAM
)&info
);
4162 int ME_CountParagraphsBetween(ME_TextEditor
*editor
, int from
, int to
)
4164 ME_DisplayItem
*item
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
4167 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= from
)
4168 item
= item
->member
.para
.next_para
;
4171 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= to
) {
4172 item
= item
->member
.para
.next_para
;
4179 int ME_GetTextW(ME_TextEditor
*editor
, WCHAR
*buffer
, int nStart
, int nChars
, int bCRLF
)
4181 ME_DisplayItem
*item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
4183 WCHAR
*pStart
= buffer
;
4190 /* bCRLF flag is only honored in 2.0 and up. 1.0 must always return text verbatim */
4191 if (editor
->bEmulateVersion10
) bCRLF
= 0;
4195 int nLen
= ME_StrLen(item
->member
.run
.strText
) - nStart
;
4198 CopyMemory(buffer
, item
->member
.run
.strText
->szData
+ nStart
, sizeof(WCHAR
)*nLen
);
4207 item
= ME_FindItemFwd(item
, diRun
);
4210 while(nChars
&& item
)
4212 int nLen
= ME_StrLen(item
->member
.run
.strText
);
4213 if (item
->member
.run
.nFlags
& MERF_ENDPARA
)
4214 nLen
= item
->member
.run
.nCR
+ item
->member
.run
.nLF
;
4218 if (item
->member
.run
.nFlags
& MERF_ENDCELL
&&
4219 item
->member
.run
.nFlags
& MERF_ENDPARA
)
4223 else if (item
->member
.run
.nFlags
& MERF_ENDPARA
)
4225 if (!ME_FindItemFwd(item
, diRun
))
4226 /* No '\r' is appended to the last paragraph. */
4228 else if (bCRLF
&& nChars
== 1) {
4234 /* richedit 2.0 case - actual line-break is \r but should report \r\n */
4235 if (ME_GetParagraph(item
)->member
.para
.nFlags
& (MEPF_ROWSTART
|MEPF_ROWEND
))
4240 *buffer
= '\n'; /* Later updated by nLen==1 at the end of the loop */
4250 /* richedit 2.0 verbatim has only \r. richedit 1.0 should honor encodings */
4252 while (nChars
- i
> 0 && i
< item
->member
.run
.nCR
)
4254 buffer
[i
] = '\r'; i
++;
4257 while (nChars
- i
- j
> 0 && j
< item
->member
.run
.nLF
)
4259 buffer
[i
+j
] = '\n'; j
++;
4265 CopyMemory(buffer
, item
->member
.run
.strText
->szData
, sizeof(WCHAR
)*nLen
);
4272 TRACE("nWritten=%d, actual=%d\n", nWritten
, buffer
-pStart
);
4276 item
= ME_FindItemFwd(item
, diRun
);
4279 TRACE("nWritten=%d, actual=%d\n", nWritten
, buffer
-pStart
);
4283 static BOOL
ME_RegisterEditorClass(HINSTANCE hInstance
)
4288 wcW
.style
= CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
;
4289 wcW
.lpfnWndProc
= RichEditWndProcW
;
4291 wcW
.cbWndExtra
= sizeof(ME_TextEditor
*);
4292 wcW
.hInstance
= NULL
; /* hInstance would register DLL-local class */
4294 wcW
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
4295 wcW
.hbrBackground
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
4296 wcW
.lpszMenuName
= NULL
;
4298 if (is_version_nt())
4300 wcW
.lpszClassName
= RichEdit20W
;
4301 if (!RegisterClassW(&wcW
)) return FALSE
;
4302 wcW
.lpszClassName
= RichEdit50W
;
4303 if (!RegisterClassW(&wcW
)) return FALSE
;
4307 /* WNDCLASSA/W have the same layout */
4308 wcW
.lpszClassName
= (LPCWSTR
)"RichEdit20W";
4309 if (!RegisterClassA((WNDCLASSA
*)&wcW
)) return FALSE
;
4310 wcW
.lpszClassName
= (LPCWSTR
)"RichEdit50W";
4311 if (!RegisterClassA((WNDCLASSA
*)&wcW
)) return FALSE
;
4314 wcA
.style
= CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
;
4315 wcA
.lpfnWndProc
= RichEditWndProcA
;
4317 wcA
.cbWndExtra
= sizeof(ME_TextEditor
*);
4318 wcA
.hInstance
= NULL
; /* hInstance would register DLL-local class */
4320 wcA
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
4321 wcA
.hbrBackground
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
4322 wcA
.lpszMenuName
= NULL
;
4323 wcA
.lpszClassName
= "RichEdit20A";
4324 if (!RegisterClassA(&wcA
)) return FALSE
;
4325 wcA
.lpszClassName
= "RichEdit50A";
4326 if (!RegisterClassA(&wcA
)) return FALSE
;
4331 LRESULT WINAPI
REComboWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
) {
4332 /* FIXME: Not implemented */
4333 TRACE("hWnd %p msg %04x (%s) %08lx %08lx\n",
4334 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
);
4335 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
4338 LRESULT WINAPI
REListWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
) {
4339 /* FIXME: Not implemented */
4340 TRACE("hWnd %p msg %04x (%s) %08lx %08lx\n",
4341 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
);
4342 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
4345 /******************************************************************
4346 * REExtendedRegisterClass (RICHED20.8)
4348 * FIXME undocumented
4349 * Need to check for errors and implement controls and callbacks
4351 LRESULT WINAPI
REExtendedRegisterClass(void)
4356 FIXME("semi stub\n");
4360 wcW
.hInstance
= NULL
;
4363 wcW
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
4364 wcW
.lpszMenuName
= NULL
;
4366 if (!ME_ListBoxRegistered
)
4368 wcW
.style
= CS_PARENTDC
| CS_DBLCLKS
| CS_GLOBALCLASS
;
4369 wcW
.lpfnWndProc
= REListWndProc
;
4370 wcW
.lpszClassName
= REListBox20W
;
4371 if (RegisterClassW(&wcW
)) ME_ListBoxRegistered
= TRUE
;
4374 if (!ME_ComboBoxRegistered
)
4376 wcW
.style
= CS_PARENTDC
| CS_DBLCLKS
| CS_GLOBALCLASS
| CS_VREDRAW
| CS_HREDRAW
;
4377 wcW
.lpfnWndProc
= REComboWndProc
;
4378 wcW
.lpszClassName
= REComboBox20W
;
4379 if (RegisterClassW(&wcW
)) ME_ComboBoxRegistered
= TRUE
;
4383 if (ME_ListBoxRegistered
)
4385 if (ME_ComboBoxRegistered
)
4391 int ME_AutoURLDetect(ME_TextEditor
*editor
, WCHAR curChar
)
4411 int curf_ef
, link_ef
, def_ef
;
4412 int cur_prefx
, prefx_cnt
;
4413 int sel_min
, sel_max
;
4416 int URLmin
, URLmax
= 0;
4418 CHARFORMAT2W cur_format
;
4419 CHARFORMAT2W default_format
;
4421 RichEditANSIWndProc(editor
->hWnd
, EM_EXGETSEL
, (WPARAM
) 0, (LPARAM
) &ins_pt
);
4422 sel_min
= ins_pt
.cpMin
;
4423 sel_max
= ins_pt
.cpMax
;
4424 if (sel_min
==sel_max
)
4426 if (sel_min
!=sel_max
)
4427 car_pos
= ME_GetTextLength(editor
)+1;
4428 cur_format
.cbSize
= sizeof(cur_format
);
4429 default_format
.cbSize
= sizeof(default_format
);
4430 RichEditANSIWndProc(editor
->hWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cur_format
);
4431 RichEditANSIWndProc(editor
->hWnd
, EM_GETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
) &default_format
);
4432 link
.cbSize
= sizeof(link
);
4433 link
.dwMask
= CFM_LINK
;
4434 link
.dwEffects
= CFE_LINK
;
4435 curf_ef
= cur_format
.dwEffects
& link
.dwEffects
;
4436 def_ef
= default_format
.dwEffects
& link
.dwEffects
;
4437 link_ef
= link
.dwEffects
& link
.dwEffects
;
4438 if (curf_ef
== link_ef
)
4440 if( curChar
== '\n' || curChar
=='\r' || curChar
==' ')
4442 ME_SetSelection(editor
, car_pos
, car_pos
);
4443 RichEditANSIWndProc(editor
->hWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &default_format
);
4448 if (curf_ef
== def_ef
)
4451 prefx_cnt
= (sizeof(prefixes
)/sizeof(struct prefix_s
))-1;
4452 while (cur_prefx
<=prefx_cnt
)
4456 ft
.lpstrText
= prefixes
[cur_prefx
].text
;
4457 URLmin
=max(0,(car_pos
-prefixes
[cur_prefx
].length
));
4458 URLmax
=max(0, car_pos
);
4459 if ((car_pos
== 0) && (ME_GetTextLength(editor
) != 0))
4461 URLmax
= ME_GetTextLength(editor
)+1;
4463 ft
.chrg
.cpMin
= URLmin
;
4464 ft
.chrg
.cpMax
= URLmax
;
4465 text_pos
=RichEditANSIWndProc(editor
->hWnd
, EM_FINDTEXT
, FR_DOWN
, (LPARAM
)&ft
);
4470 ME_SetCharFormat(editor
, text_pos
, (URLmax
-text_pos
), &link
);
4471 ME_RewrapRepaint(editor
);
4480 static BOOL
isurlspecial(WCHAR c
)
4482 static const WCHAR special_chars
[] = {'.','/','%','@','*','|','\\','+','#',0};
4483 return strchrW( special_chars
, c
) != NULL
;
4487 * This proc takes a selection, and scans it forward in order to select the span
4488 * of a possible URL candidate. A possible URL candidate must start with isalnum
4489 * or one of the following special characters: *|/\+%#@ and must consist entirely
4490 * of the characters allowed to start the URL, plus : (colon) which may occur
4491 * at most once, and not at either end.
4493 * sel_max == -1 indicates scan to end of text.
4495 BOOL
ME_FindNextURLCandidate(ME_TextEditor
*editor
, int sel_min
, int sel_max
,
4496 int * candidate_min
, int * candidate_max
)
4498 ME_DisplayItem
* item
;
4499 ME_DisplayItem
* para
;
4501 BOOL foundColon
= FALSE
;
4502 WCHAR lastAcceptedChar
= '\0';
4504 TRACE("sel_min = %d sel_max = %d\n", sel_min
, sel_max
);
4506 *candidate_min
= *candidate_max
= -1;
4507 item
= ME_FindItemAtOffset(editor
, diRun
, sel_min
, &nStart
);
4508 if (!item
) return FALSE
;
4509 TRACE("nStart = %d\n", nStart
);
4510 para
= ME_GetParagraph(item
);
4511 if (sel_max
== -1) sel_max
= ME_GetTextLength(editor
);
4512 while (item
&& para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
< sel_max
)
4514 ME_DisplayItem
* next_item
;
4516 if (!(item
->member
.run
.nFlags
& MERF_ENDPARA
)) {
4517 /* Find start of candidate */
4518 if (*candidate_min
== -1) {
4519 while (nStart
< ME_StrLen(item
->member
.run
.strText
) &&
4520 !(isalnumW(item
->member
.run
.strText
->szData
[nStart
]) ||
4521 isurlspecial(item
->member
.run
.strText
->szData
[nStart
]))) {
4524 if (nStart
< ME_StrLen(item
->member
.run
.strText
) &&
4525 (isalnumW(item
->member
.run
.strText
->szData
[nStart
]) ||
4526 isurlspecial(item
->member
.run
.strText
->szData
[nStart
]))) {
4527 *candidate_min
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
;
4528 lastAcceptedChar
= item
->member
.run
.strText
->szData
[nStart
];
4533 /* Find end of candidate */
4534 if (*candidate_min
>= 0) {
4535 while (nStart
< ME_StrLen(item
->member
.run
.strText
) &&
4536 (isalnumW(item
->member
.run
.strText
->szData
[nStart
]) ||
4537 isurlspecial(item
->member
.run
.strText
->szData
[nStart
]) ||
4538 (!foundColon
&& item
->member
.run
.strText
->szData
[nStart
] == ':') )) {
4539 if (item
->member
.run
.strText
->szData
[nStart
] == ':') foundColon
= TRUE
;
4540 lastAcceptedChar
= item
->member
.run
.strText
->szData
[nStart
];
4543 if (nStart
< ME_StrLen(item
->member
.run
.strText
) &&
4544 !(isalnumW(item
->member
.run
.strText
->szData
[nStart
]) ||
4545 isurlspecial(item
->member
.run
.strText
->szData
[nStart
]) )) {
4546 *candidate_max
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
;
4548 if (lastAcceptedChar
== ':') (*candidate_max
)--;
4553 /* End of paragraph: skip it if before candidate span, or terminates
4554 current active span */
4555 if (*candidate_min
>= 0) {
4556 *candidate_max
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
;
4557 if (lastAcceptedChar
== ':') (*candidate_max
)--;
4562 /* Reaching this point means no span was found, so get next span */
4563 next_item
= ME_FindItemFwd(item
, diRun
);
4565 if (*candidate_min
>= 0) {
4566 /* There are no further runs, so take end of text as end of candidate */
4567 *candidate_max
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
;
4568 if (lastAcceptedChar
== ':') (*candidate_max
)--;
4573 para
= ME_GetParagraph(item
);
4578 if (*candidate_min
>= 0) {
4579 /* There are no further runs, so take end of text as end of candidate */
4580 *candidate_max
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
;
4581 if (lastAcceptedChar
== ':') (*candidate_max
)--;
4589 * This proc evaluates the selection and returns TRUE if it can be considered an URL
4591 BOOL
ME_IsCandidateAnURL(ME_TextEditor
*editor
, int sel_min
, int sel_max
)
4597 /* Code below depends on these being in decreasing length order! */
4611 LPWSTR bufferW
= NULL
;
4615 if (sel_max
== -1) sel_max
= ME_GetTextLength(editor
);
4616 assert(sel_min
<= sel_max
);
4617 for (i
= 0; i
< sizeof(prefixes
) / sizeof(struct prefix_s
); i
++)
4619 if (sel_max
- sel_min
< prefixes
[i
].length
) continue;
4620 if (bufferW
== NULL
) {
4621 bufferW
= (LPWSTR
)heap_alloc((sel_max
- sel_min
+ 1) * sizeof(WCHAR
));
4623 ME_GetTextW(editor
, bufferW
, sel_min
, min(sel_max
- sel_min
, strlen(prefixes
[i
].text
)), 0);
4624 MultiByteToWideChar(CP_ACP
, 0, prefixes
[i
].text
, -1, bufW
, 32);
4625 if (!lstrcmpW(bufW
, bufferW
))
4636 * This proc walks through the indicated selection and evaluates whether each
4637 * section identified by ME_FindNextURLCandidate and in-between sections have
4638 * their proper CFE_LINK attributes set or unset. If the CFE_LINK attribute is
4639 * not what it is supposed to be, this proc sets or unsets it as appropriate.
4641 * Returns TRUE if at least one section was modified.
4643 BOOL
ME_UpdateLinkAttribute(ME_TextEditor
*editor
, int sel_min
, int sel_max
)
4645 BOOL modified
= FALSE
;
4648 if (sel_max
== -1) sel_max
= ME_GetTextLength(editor
);
4655 if (ME_FindNextURLCandidate(editor
, sel_min
, sel_max
, &cMin
, &cMax
))
4657 /* Section before candidate is not an URL */
4658 beforeURL
[0] = sel_min
;
4659 beforeURL
[1] = cMin
;
4661 if (ME_IsCandidateAnURL(editor
, cMin
, cMax
))
4663 inURL
[0] = cMin
; inURL
[1] = cMax
;
4667 beforeURL
[1] = cMax
;
4668 inURL
[0] = inURL
[1] = -1;
4674 /* No more candidates until end of selection */
4675 beforeURL
[0] = sel_min
;
4676 beforeURL
[1] = sel_max
;
4677 inURL
[0] = inURL
[1] = -1;
4681 if (beforeURL
[0] < beforeURL
[1])
4683 /* CFE_LINK effect should be consistently unset */
4684 link
.cbSize
= sizeof(link
);
4685 ME_GetCharFormat(editor
, beforeURL
[0], beforeURL
[1], &link
);
4686 if (!(link
.dwMask
& CFM_LINK
) || (link
.dwEffects
& CFE_LINK
))
4688 /* CFE_LINK must be unset from this range */
4689 memset(&link
, 0, sizeof(CHARFORMAT2W
));
4690 link
.cbSize
= sizeof(link
);
4691 link
.dwMask
= CFM_LINK
;
4693 ME_SetCharFormat(editor
, beforeURL
[0], beforeURL
[1] - beforeURL
[0], &link
);
4697 if (inURL
[0] < inURL
[1])
4699 /* CFE_LINK effect should be consistently set */
4700 link
.cbSize
= sizeof(link
);
4701 ME_GetCharFormat(editor
, inURL
[0], inURL
[1], &link
);
4702 if (!(link
.dwMask
& CFM_LINK
) || !(link
.dwEffects
& CFE_LINK
))
4704 /* CFE_LINK must be set on this range */
4705 memset(&link
, 0, sizeof(CHARFORMAT2W
));
4706 link
.cbSize
= sizeof(link
);
4707 link
.dwMask
= CFM_LINK
;
4708 link
.dwEffects
= CFE_LINK
;
4709 ME_SetCharFormat(editor
, inURL
[0], inURL
[1] - inURL
[0], &link
);
4713 } while (sel_min
< sel_max
);
4717 void ME_UpdateSelectionLinkAttribute(ME_TextEditor
*editor
)
4719 ME_DisplayItem
* startPara
, * endPara
;
4720 ME_DisplayItem
* item
;
4724 ME_GetSelection(editor
, &from
, &to
);
4725 if (from
> to
) from
^= to
, to
^=from
, from
^= to
;
4726 startPara
= NULL
; endPara
= NULL
;
4728 /* Find paragraph previous to the one that contains start cursor */
4729 item
= ME_FindItemAtOffset(editor
, diRun
, from
, &dummy
);
4731 startPara
= ME_FindItemBack(item
, diParagraph
);
4732 item
= ME_FindItemBack(startPara
, diParagraph
);
4733 if (item
) startPara
= item
;
4736 /* Find paragraph that contains end cursor */
4737 item
= ME_FindItemAtOffset(editor
, diRun
, to
, &dummy
);
4739 endPara
= ME_FindItemFwd(item
, diParagraph
);
4742 if (startPara
&& endPara
) {
4743 ME_UpdateLinkAttribute(editor
,
4744 startPara
->member
.para
.nCharOfs
,
4745 endPara
->member
.para
.nCharOfs
);
4746 } else if (startPara
) {
4747 ME_UpdateLinkAttribute(editor
,
4748 startPara
->member
.para
.nCharOfs
,