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_RTFCharAttrHook(RTF_Info
*info
)
326 fmt
.cbSize
= sizeof(fmt
);
330 switch(info
->rtfMinor
)
333 /* FIXME add more flags once they're implemented */
334 fmt
.dwMask
= CFM_BOLD
| CFM_ITALIC
| CFM_UNDERLINETYPE
| CFM_STRIKEOUT
| CFM_COLOR
| CFM_BACKCOLOR
| CFM_SIZE
| CFM_WEIGHT
;
335 fmt
.dwEffects
= CFE_AUTOCOLOR
| CFE_AUTOBACKCOLOR
;
336 fmt
.yHeight
= 12*20; /* 12pt */
337 fmt
.wWeight
= FW_NORMAL
;
338 fmt
.bUnderlineType
= CFU_UNDERLINENONE
;
341 fmt
.dwMask
= CFM_BOLD
| CFM_WEIGHT
;
342 fmt
.dwEffects
= info
->rtfParam
? CFE_BOLD
: 0;
343 fmt
.wWeight
= info
->rtfParam
? FW_BOLD
: FW_NORMAL
;
346 fmt
.dwMask
= CFM_ITALIC
;
347 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
350 fmt
.dwMask
= CFM_UNDERLINETYPE
;
351 fmt
.bUnderlineType
= info
->rtfParam
? CFU_CF1UNDERLINE
: CFU_UNDERLINENONE
;
353 case rtfDotUnderline
:
354 fmt
.dwMask
= CFM_UNDERLINETYPE
;
355 fmt
.bUnderlineType
= info
->rtfParam
? CFU_UNDERLINEDOTTED
: CFU_UNDERLINENONE
;
358 fmt
.dwMask
= CFM_UNDERLINETYPE
;
359 fmt
.bUnderlineType
= info
->rtfParam
? CFU_UNDERLINEDOUBLE
: CFU_UNDERLINENONE
;
361 case rtfWordUnderline
:
362 fmt
.dwMask
= CFM_UNDERLINETYPE
;
363 fmt
.bUnderlineType
= info
->rtfParam
? CFU_UNDERLINEWORD
: CFU_UNDERLINENONE
;
366 fmt
.dwMask
= CFM_UNDERLINETYPE
;
367 fmt
.bUnderlineType
= CFU_UNDERLINENONE
;
370 fmt
.dwMask
= CFM_STRIKEOUT
;
371 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
375 case rtfSubScrShrink
:
376 case rtfSuperScrShrink
:
378 fmt
.dwMask
= CFM_SUBSCRIPT
|CFM_SUPERSCRIPT
;
379 if (info
->rtfMinor
== rtfSubScrShrink
) fmt
.dwEffects
= CFE_SUBSCRIPT
;
380 if (info
->rtfMinor
== rtfSuperScrShrink
) fmt
.dwEffects
= CFE_SUPERSCRIPT
;
381 if (info
->rtfMinor
== rtfNoSuperSub
) fmt
.dwEffects
= 0;
384 fmt
.dwMask
= CFM_HIDDEN
;
385 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
388 fmt
.dwMask
= CFM_BACKCOLOR
;
390 if (info
->rtfParam
== 0)
391 fmt
.dwEffects
= CFE_AUTOBACKCOLOR
;
392 else if (info
->rtfParam
!= rtfNoParam
)
394 RTFColor
*c
= RTFGetColor(info
, info
->rtfParam
);
395 fmt
.crTextColor
= (c
->rtfCBlue
<<16)|(c
->rtfCGreen
<<8)|(c
->rtfCRed
);
399 fmt
.dwMask
= CFM_COLOR
;
401 if (info
->rtfParam
== 0)
402 fmt
.dwEffects
= CFE_AUTOCOLOR
;
403 else if (info
->rtfParam
!= rtfNoParam
)
405 RTFColor
*c
= RTFGetColor(info
, info
->rtfParam
);
407 fmt
.crTextColor
= (c
->rtfCBlue
<<16)|(c
->rtfCGreen
<<8)|(c
->rtfCRed
);
413 if (info
->rtfParam
!= rtfNoParam
)
415 RTFFont
*f
= RTFGetFont(info
, info
->rtfParam
);
418 MultiByteToWideChar(CP_ACP
, 0, f
->rtfFName
, -1, fmt
.szFaceName
, sizeof(fmt
.szFaceName
)/sizeof(WCHAR
));
419 fmt
.szFaceName
[sizeof(fmt
.szFaceName
)/sizeof(WCHAR
)-1] = '\0';
420 fmt
.bCharSet
= f
->rtfFCharSet
;
421 fmt
.dwMask
= CFM_FACE
| CFM_CHARSET
;
422 fmt
.bPitchAndFamily
= f
->rtfFPitch
| (f
->rtfFFamily
<< 4);
427 fmt
.dwMask
= CFM_SIZE
;
428 if (info
->rtfParam
!= rtfNoParam
)
429 fmt
.yHeight
= info
->rtfParam
*10;
434 RTFFlushOutputBuffer(info
);
435 /* FIXME too slow ? how come ? */
436 style2
= ME_ApplyStyle(info
->style
, &fmt
);
437 ME_ReleaseStyle(info
->style
);
438 info
->style
= style2
;
439 info
->styleChanged
= TRUE
;
443 /* FIXME this function doesn't get any information about context of the RTF tag, which is very bad,
444 the same tags mean different things in different contexts */
445 static void ME_RTFParAttrHook(RTF_Info
*info
)
448 fmt
.cbSize
= sizeof(fmt
);
451 switch(info
->rtfMinor
)
453 case rtfParDef
: /* restores default paragraph attributes */
454 fmt
.dwMask
= PFM_ALIGNMENT
| PFM_BORDER
| PFM_LINESPACING
| PFM_TABSTOPS
| PFM_OFFSET
|
455 PFM_RIGHTINDENT
| PFM_SPACEAFTER
| PFM_SPACEBEFORE
| PFM_STARTINDENT
| PFM_TABLE
;
456 /* TODO: numbering, shading */
457 fmt
.wAlignment
= PFA_LEFT
;
459 fmt
.dxOffset
= fmt
.dxStartIndent
= fmt
.dxRightIndent
= 0;
460 fmt
.wBorderWidth
= fmt
.wBorders
= 0;
461 fmt
.wBorderSpace
= 0;
462 fmt
.bLineSpacingRule
= 0;
463 fmt
.dySpaceBefore
= fmt
.dySpaceAfter
= 0;
464 fmt
.dyLineSpacing
= 0;
465 fmt
.wEffects
&= ~PFE_TABLE
;
469 ME_DisplayItem
*para
;
471 RTFFlushOutputBuffer(info
);
472 para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
473 assert(para
->member
.para
.pCells
);
474 fmt
.dwMask
|= PFM_TABLE
;
475 fmt
.wEffects
|= PFE_TABLE
;
479 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
480 fmt
.dwMask
|= PFM_STARTINDENT
| PFM_OFFSET
;
481 fmt
.dxStartIndent
+= info
->rtfParam
;
482 fmt
.dxOffset
= -info
->rtfParam
;
485 /* we assume rtfLeftIndent is always specified before rtfFirstIndent */
486 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
487 fmt
.dwMask
|= PFM_STARTINDENT
;
488 fmt
.dxStartIndent
= info
->rtfParam
;
492 fmt
.dwMask
= PFM_RIGHTINDENT
;
493 fmt
.dxRightIndent
= info
->rtfParam
;
497 fmt
.dwMask
= PFM_ALIGNMENT
;
498 fmt
.wAlignment
= PFA_LEFT
;
501 fmt
.dwMask
= PFM_ALIGNMENT
;
502 fmt
.wAlignment
= PFA_RIGHT
;
505 fmt
.dwMask
= PFM_ALIGNMENT
;
506 fmt
.wAlignment
= PFA_CENTER
;
509 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
510 if (!(fmt
.dwMask
& PFM_TABSTOPS
))
512 fmt
.dwMask
|= PFM_TABSTOPS
;
515 if (fmt
.cTabCount
< MAX_TAB_STOPS
)
516 fmt
.rgxTabs
[fmt
.cTabCount
++] = info
->rtfParam
;
519 fmt
.dwMask
= PFM_KEEP
;
520 fmt
.wEffects
= PFE_KEEP
;
522 case rtfNoWidowControl
:
523 fmt
.dwMask
= PFM_NOWIDOWCONTROL
;
524 fmt
.wEffects
= PFE_NOWIDOWCONTROL
;
527 fmt
.dwMask
= PFM_KEEPNEXT
;
528 fmt
.wEffects
= PFE_KEEPNEXT
;
531 fmt
.dwMask
= PFM_SPACEAFTER
;
532 fmt
.dySpaceAfter
= info
->rtfParam
;
535 fmt
.dwMask
= PFM_SPACEBEFORE
;
536 fmt
.dySpaceBefore
= info
->rtfParam
;
538 case rtfSpaceBetween
:
539 fmt
.dwMask
= PFM_LINESPACING
;
540 if ((int)info
->rtfParam
> 0)
542 fmt
.dyLineSpacing
= info
->rtfParam
;
543 fmt
.bLineSpacingRule
= 3;
547 fmt
.dyLineSpacing
= info
->rtfParam
;
548 fmt
.bLineSpacingRule
= 4;
550 case rtfSpaceMultiply
:
551 fmt
.dwMask
= PFM_LINESPACING
;
552 fmt
.dyLineSpacing
= info
->rtfParam
* 20;
553 fmt
.bLineSpacingRule
= 5;
556 fmt
.dwMask
= PFM_NUMBERING
;
557 fmt
.wNumbering
= PFN_BULLET
;
560 fmt
.dwMask
= PFM_NUMBERING
;
561 fmt
.wNumbering
= 2; /* FIXME: MSDN says it's not used ?? */
563 case rtfParNumDecimal
:
564 fmt
.dwMask
= PFM_NUMBERING
;
565 fmt
.wNumbering
= 2; /* FIXME: MSDN says it's not used ?? */
567 case rtfParNumIndent
:
568 fmt
.dwMask
= PFM_NUMBERINGTAB
;
569 fmt
.wNumberingTab
= info
->rtfParam
;
571 case rtfParNumStartAt
:
572 fmt
.dwMask
= PFM_NUMBERINGSTART
;
573 fmt
.wNumberingStart
= info
->rtfParam
;
576 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
577 if (!(fmt
.dwMask
& PFM_BORDER
))
579 fmt
.dwMask
|= PFM_BORDER
;
580 fmt
.wBorderSpace
= 0;
581 fmt
.wBorderWidth
= 1;
587 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
588 if (!(fmt
.dwMask
& PFM_BORDER
))
590 fmt
.dwMask
|= PFM_BORDER
;
591 fmt
.wBorderSpace
= 0;
592 fmt
.wBorderWidth
= 1;
598 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
599 if (!(fmt
.dwMask
& PFM_BORDER
))
601 fmt
.dwMask
|= PFM_BORDER
;
602 fmt
.wBorderSpace
= 0;
603 fmt
.wBorderWidth
= 1;
608 case rtfBorderBottom
:
609 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
610 if (!(fmt
.dwMask
& PFM_BORDER
))
612 fmt
.dwMask
|= PFM_BORDER
;
613 fmt
.wBorderSpace
= 0;
614 fmt
.wBorderWidth
= 1;
619 case rtfBorderSingle
:
620 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
621 /* we assume that borders have been created before (RTF spec) */
622 fmt
.wBorders
&= ~0x700;
623 fmt
.wBorders
|= 1 << 8;
626 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
627 /* we assume that borders have been created before (RTF spec) */
628 fmt
.wBorders
&= ~0x700;
629 fmt
.wBorders
|= 2 << 8;
631 case rtfBorderShadow
:
632 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
633 /* we assume that borders have been created before (RTF spec) */
634 fmt
.wBorders
&= ~0x700;
635 fmt
.wBorders
|= 10 << 8;
637 case rtfBorderDouble
:
638 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
639 /* we assume that borders have been created before (RTF spec) */
640 fmt
.wBorders
&= ~0x700;
641 fmt
.wBorders
|= 7 << 8;
644 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
645 /* we assume that borders have been created before (RTF spec) */
646 fmt
.wBorders
&= ~0x700;
647 fmt
.wBorders
|= 11 << 8;
650 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
651 /* we assume that borders have been created before (RTF spec) */
652 fmt
.wBorderWidth
|= ((info
->rtfParam
/ 15) & 7) << 8;
655 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
656 /* we assume that borders have been created before (RTF spec) */
657 fmt
.wBorderSpace
= info
->rtfParam
;
661 RTFFlushOutputBuffer(info
);
662 /* FIXME too slow ? how come ?*/
663 ME_SetSelectionParaFormat(info
->editor
, &fmt
);
667 static void ME_RTFTblAttrHook(RTF_Info
*info
)
669 ME_DisplayItem
*para
;
671 switch (info
->rtfMinor
)
674 RTFFlushOutputBuffer(info
);
675 para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
677 /* Release possibly inherited cell definitions */
678 ME_DestroyTableCellList(para
);
680 para
->member
.para
.pCells
= ALLOC_OBJ(ME_TableCell
);
681 para
->member
.para
.pCells
->nRightBoundary
= 0;
682 para
->member
.para
.pCells
->next
= NULL
;
683 para
->member
.para
.pLastCell
= para
->member
.para
.pCells
;
686 RTFFlushOutputBuffer(info
);
687 para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
689 if (para
->member
.para
.pLastCell
->nRightBoundary
)
691 ME_TableCell
*pCell
= ALLOC_OBJ(ME_TableCell
);
694 para
->member
.para
.pLastCell
->next
= pCell
;
695 para
->member
.para
.pLastCell
= pCell
;
697 para
->member
.para
.pLastCell
->nRightBoundary
= info
->rtfParam
;
702 static BOOL
ME_RTFInsertOleObject(RTF_Info
*info
, HENHMETAFILE hemf
, HBITMAP hbmp
,
705 LPOLEOBJECT lpObject
= NULL
;
706 LPSTORAGE lpStorage
= NULL
;
707 LPOLECLIENTSITE lpClientSite
= NULL
;
708 LPDATAOBJECT lpDataObject
= NULL
;
709 LPOLECACHE lpOleCache
= NULL
;
718 stgm
.tymed
= TYMED_ENHMF
;
719 stgm
.u
.hEnhMetaFile
= hemf
;
720 fm
.cfFormat
= CF_ENHMETAFILE
;
724 stgm
.tymed
= TYMED_GDI
;
725 stgm
.u
.hBitmap
= hbmp
;
726 fm
.cfFormat
= CF_BITMAP
;
728 stgm
.pUnkForRelease
= NULL
;
731 fm
.dwAspect
= DVASPECT_CONTENT
;
733 fm
.tymed
= stgm
.tymed
;
735 if (!info
->lpRichEditOle
)
737 CreateIRichEditOle(info
->editor
, (VOID
**)&info
->lpRichEditOle
);
740 if (OleCreateDefaultHandler(&CLSID_NULL
, NULL
, &IID_IOleObject
, (void**)&lpObject
) == S_OK
&&
742 /* FIXME: enable it when rich-edit properly implements this method */
743 IRichEditOle_GetClientSite(info
->lpRichEditOle
, &lpClientSite
) == S_OK
&&
744 IOleObject_SetClientSite(lpObject
, lpClientSite
) == S_OK
&&
746 IOleObject_GetUserClassID(lpObject
, &clsid
) == S_OK
&&
747 IOleObject_QueryInterface(lpObject
, &IID_IOleCache
, (void**)&lpOleCache
) == S_OK
&&
748 IOleCache_Cache(lpOleCache
, &fm
, 0, &conn
) == S_OK
&&
749 IOleObject_QueryInterface(lpObject
, &IID_IDataObject
, (void**)&lpDataObject
) == S_OK
&&
750 IDataObject_SetData(lpDataObject
, &fm
, &stgm
, TRUE
) == S_OK
)
754 reobject
.cbStruct
= sizeof(reobject
);
755 reobject
.cp
= REO_CP_SELECTION
;
756 reobject
.clsid
= clsid
;
757 reobject
.poleobj
= lpObject
;
758 reobject
.pstg
= lpStorage
;
759 reobject
.polesite
= lpClientSite
;
760 /* convert from twips to .01 mm */
761 reobject
.sizel
.cx
= MulDiv(sz
->cx
, 254, 144);
762 reobject
.sizel
.cy
= MulDiv(sz
->cy
, 254, 144);
763 reobject
.dvaspect
= DVASPECT_CONTENT
;
764 reobject
.dwFlags
= 0; /* FIXME */
767 /* FIXME: could be simpler */
768 ret
= IRichEditOle_InsertObject(info
->lpRichEditOle
, &reobject
) == S_OK
;
771 if (lpObject
) IOleObject_Release(lpObject
);
772 if (lpClientSite
) IOleClientSite_Release(lpClientSite
);
773 if (lpStorage
) IStorage_Release(lpStorage
);
774 if (lpDataObject
) IDataObject_Release(lpDataObject
);
775 if (lpOleCache
) IOleCache_Release(lpOleCache
);
780 static void ME_RTFReadPictGroup(RTF_Info
*info
)
784 unsigned bufsz
, bufidx
;
790 enum gfxkind
{gfx_unknown
= 0, gfx_enhmetafile
, gfx_metafile
, gfx_dib
} gfx
= gfx_unknown
;
793 if (info
->rtfClass
== rtfEOF
)
796 /* fetch picture type */
797 if (RTFCheckMM (info
, rtfPictAttr
, rtfWinMetafile
))
799 mfp
.mm
= info
->rtfParam
;
802 else if (RTFCheckMM (info
, rtfPictAttr
, rtfDevIndBitmap
))
804 if (info
->rtfParam
!= 0) FIXME("dibitmap should be 0 (%d)\n", info
->rtfParam
);
807 else if (RTFCheckMM (info
, rtfPictAttr
, rtfEmfBlip
))
809 gfx
= gfx_enhmetafile
;
813 FIXME("%d %d\n", info
->rtfMajor
, info
->rtfMinor
);
817 /* fetch picture attributes */
821 if (info
->rtfClass
== rtfEOF
)
823 if (info
->rtfClass
== rtfText
)
825 if (!RTFCheckCM (info
, rtfControl
, rtfPictAttr
))
827 ERR("Expected picture attribute (%d %d)\n",
828 info
->rtfClass
, info
->rtfMajor
);
831 else if (RTFCheckMM (info
, rtfPictAttr
, rtfPicWid
))
833 if (gfx
== gfx_metafile
) mfp
.xExt
= info
->rtfParam
;
835 else if (RTFCheckMM (info
, rtfPictAttr
, rtfPicHt
))
837 if (gfx
== gfx_metafile
) mfp
.yExt
= info
->rtfParam
;
839 else if (RTFCheckMM (info
, rtfPictAttr
, rtfPicGoalWid
))
840 sz
.cx
= info
->rtfParam
;
841 else if (RTFCheckMM (info
, rtfPictAttr
, rtfPicGoalHt
))
842 sz
.cy
= info
->rtfParam
;
844 FIXME("Non supported attribute: %d %d %d\n", info
->rtfClass
, info
->rtfMajor
, info
->rtfMinor
);
846 /* fetch picture data */
849 buffer
= HeapAlloc(GetProcessHeap(), 0, bufsz
);
850 val
= info
->rtfMajor
;
851 for (flip
= TRUE
;; flip
= !flip
)
854 if (info
->rtfClass
== rtfEOF
)
856 HeapFree(GetProcessHeap(), 0, buffer
);
857 return; /* Warn ?? */
859 if (RTFCheckCM(info
, rtfGroup
, rtfEndGroup
))
861 if (info
->rtfClass
!= rtfText
) goto skip_group
;
864 if (bufidx
>= bufsz
&&
865 !(buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
, bufsz
+= 1024)))
867 buffer
[bufidx
++] = RTFCharToHex(val
) * 16 + RTFCharToHex(info
->rtfMajor
);
870 val
= info
->rtfMajor
;
872 if (flip
) FIXME("wrong hex string\n");
876 case gfx_enhmetafile
:
877 if ((hemf
= SetEnhMetaFileBits(bufidx
, buffer
)))
878 ME_RTFInsertOleObject(info
, hemf
, NULL
, &sz
);
881 if ((hemf
= SetWinMetaFileBits(bufidx
, buffer
, NULL
, &mfp
)))
882 ME_RTFInsertOleObject(info
, hemf
, NULL
, &sz
);
886 BITMAPINFO
* bi
= (BITMAPINFO
*)buffer
;
888 unsigned nc
= bi
->bmiHeader
.biClrUsed
;
890 /* not quite right, especially for bitfields type of compression */
891 if (!nc
&& bi
->bmiHeader
.biBitCount
<= 8)
892 nc
= 1 << bi
->bmiHeader
.biBitCount
;
893 if ((hbmp
= CreateDIBitmap(hdc
, &bi
->bmiHeader
,
894 CBM_INIT
, (char*)(bi
+ 1) + nc
* sizeof(RGBQUAD
),
895 bi
, DIB_RGB_COLORS
)))
896 ME_RTFInsertOleObject(info
, NULL
, hbmp
, &sz
);
903 HeapFree(GetProcessHeap(), 0, buffer
);
904 RTFRouteToken (info
); /* feed "}" back to router */
907 HeapFree(GetProcessHeap(), 0, buffer
);
909 RTFRouteToken(info
); /* feed "}" back to router */
912 /* for now, lookup the \result part and use it, whatever the object */
913 static void ME_RTFReadObjectGroup(RTF_Info
*info
)
918 if (info
->rtfClass
== rtfEOF
)
920 if (RTFCheckCM(info
, rtfGroup
, rtfEndGroup
))
922 if (RTFCheckCM(info
, rtfGroup
, rtfBeginGroup
))
925 if (info
->rtfClass
== rtfEOF
)
927 if (RTFCheckCMM(info
, rtfControl
, rtfDestination
, rtfObjResult
))
931 while (RTFGetToken (info
) != rtfEOF
)
933 if (info
->rtfClass
== rtfGroup
)
935 if (info
->rtfMajor
== rtfBeginGroup
) level
++;
936 else if (info
->rtfMajor
== rtfEndGroup
&& --level
< 0) break;
941 else RTFSkipGroup(info
);
944 if (!RTFCheckCM (info
, rtfControl
, rtfObjAttr
))
946 FIXME("Non supported attribute: %d %d %d\n", info
->rtfClass
, info
->rtfMajor
, info
->rtfMinor
);
950 RTFRouteToken(info
); /* feed "}" back to router */
953 static void ME_RTFReadHook(RTF_Info
*info
) {
954 switch(info
->rtfClass
)
957 switch(info
->rtfMajor
)
960 if (info
->stackTop
< maxStack
) {
961 info
->stack
[info
->stackTop
].fmt
= info
->style
->fmt
;
962 info
->stack
[info
->stackTop
].codePage
= info
->codePage
;
963 info
->stack
[info
->stackTop
].unicodeLength
= info
->unicodeLength
;
966 info
->styleChanged
= FALSE
;
971 RTFFlushOutputBuffer(info
);
973 if (info
->stackTop
<=0) {
974 info
->rtfClass
= rtfEOF
;
977 assert(info
->stackTop
>= 0);
978 if (info
->styleChanged
)
980 /* FIXME too slow ? how come ? */
981 s
= ME_ApplyStyle(info
->style
, &info
->stack
[info
->stackTop
].fmt
);
982 ME_ReleaseStyle(info
->style
);
984 info
->codePage
= info
->stack
[info
->stackTop
].codePage
;
985 info
->unicodeLength
= info
->stack
[info
->stackTop
].unicodeLength
;
992 switch(info
->rtfMajor
)
995 ME_RTFCharAttrHook(info
);
998 ME_RTFParAttrHook(info
);
1001 ME_RTFTblAttrHook(info
);
1003 case rtfSpecialChar
:
1004 if (info
->rtfMinor
== rtfCell
)
1006 RTFFlushOutputBuffer(info
);
1007 ME_InsertTableCellFromCursor(info
->editor
, 0);
1015 ME_StreamInFill(ME_InStream
*stream
)
1017 stream
->editstream
->dwError
= stream
->editstream
->pfnCallback(stream
->editstream
->dwCookie
,
1018 (BYTE
*)stream
->buffer
,
1019 sizeof(stream
->buffer
),
1020 (LONG
*)&stream
->dwSize
);
1024 static LRESULT
ME_StreamIn(ME_TextEditor
*editor
, DWORD format
, EDITSTREAM
*stream
, BOOL stripLastCR
)
1028 int from
, to
, to2
, nUndoMode
;
1029 int nEventMask
= editor
->nEventMask
;
1030 ME_InStream inStream
;
1031 BOOL invalidRTF
= FALSE
;
1033 TRACE("stream==%p hWnd==%p format==0x%X\n", stream
, editor
->hWnd
, format
);
1034 editor
->nEventMask
= 0;
1036 ME_GetSelection(editor
, &from
, &to
);
1037 if ((format
& SFF_SELECTION
) && (editor
->mode
& TM_RICHTEXT
)) {
1038 style
= ME_GetSelectionInsertStyle(editor
);
1040 ME_InternalDeleteText(editor
, from
, to
-from
);
1043 ME_DisplayItem
*para_item
;
1044 style
= editor
->pBuffer
->pDefaultStyle
;
1045 ME_AddRefStyle(style
);
1046 SendMessageA(editor
->hWnd
, EM_SETSEL
, 0, 0);
1047 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
));
1049 ME_ClearTempStyle(editor
);
1051 para_item
= ME_GetParagraph(editor
->pCursors
[0].pRun
);
1052 ME_SetDefaultParaFormat(para_item
->member
.para
.pFmt
);
1056 /* Back up undo mode to a local variable */
1057 nUndoMode
= editor
->nUndoMode
;
1059 /* Only create an undo if SFF_SELECTION is set */
1060 if (!(format
& SFF_SELECTION
))
1061 editor
->nUndoMode
= umIgnore
;
1063 inStream
.editstream
= stream
;
1064 inStream
.editstream
->dwError
= 0;
1065 inStream
.dwSize
= 0;
1066 inStream
.dwUsed
= 0;
1068 if (format
& SF_RTF
)
1070 /* Check if it's really RTF, and if it is not, use plain text */
1071 ME_StreamInFill(&inStream
);
1072 if (!inStream
.editstream
->dwError
)
1074 if ((!editor
->bEmulateVersion10
&& strncmp(inStream
.buffer
, "{\\rtf", 5) && strncmp(inStream
.buffer
, "{\\urtf", 6))
1075 || (editor
->bEmulateVersion10
&& *inStream
.buffer
!= '{'))
1078 inStream
.editstream
->dwError
= -16;
1083 if (!invalidRTF
&& !inStream
.editstream
->dwError
)
1085 if (format
& SF_RTF
) {
1086 /* setup the RTF parser */
1087 memset(&parser
, 0, sizeof parser
);
1088 RTFSetEditStream(&parser
, &inStream
);
1089 parser
.rtfFormat
= format
&(SF_TEXT
|SF_RTF
);
1090 parser
.hwndEdit
= editor
->hWnd
;
1091 parser
.editor
= editor
;
1092 parser
.style
= style
;
1093 WriterInit(&parser
);
1095 RTFSetReadHook(&parser
, ME_RTFReadHook
);
1096 RTFSetDestinationCallback(&parser
, rtfPict
, ME_RTFReadPictGroup
);
1097 RTFSetDestinationCallback(&parser
, rtfObject
, ME_RTFReadObjectGroup
);
1100 /* do the parsing */
1102 RTFFlushOutputBuffer(&parser
);
1103 RTFDestroy(&parser
);
1104 if (parser
.lpRichEditOle
)
1105 IRichEditOle_Release(parser
.lpRichEditOle
);
1107 if (!inStream
.editstream
->dwError
&& parser
.stackTop
> 0)
1108 inStream
.editstream
->dwError
= HRESULT_FROM_WIN32(ERROR_HANDLE_EOF
);
1110 /* Remove last line break, as mandated by tests. This is not affected by
1111 CR/LF counters, since RTF streaming presents only \para tokens, which
1112 are converted according to the standard rules: \r for 2.0, \r\n for 1.0
1116 ME_GetSelection(editor
, &newfrom
, &newto
);
1117 if (newto
> to
+ (editor
->bEmulateVersion10
? 1 : 0)) {
1118 WCHAR lastchar
[3] = {'\0', '\0'};
1119 int linebreakSize
= editor
->bEmulateVersion10
? 2 : 1;
1121 ME_GetTextW(editor
, lastchar
, newto
- linebreakSize
, linebreakSize
, 0);
1122 if (lastchar
[0] == '\r' && (lastchar
[1] == '\n' || lastchar
[1] == '\0')) {
1123 ME_InternalDeleteText(editor
, newto
- linebreakSize
, linebreakSize
);
1128 style
= parser
.style
;
1130 else if (format
& SF_TEXT
)
1131 ME_StreamInText(editor
, format
, &inStream
, style
);
1133 ERR("EM_STREAMIN without SF_TEXT or SF_RTF\n");
1134 ME_GetSelection(editor
, &to
, &to2
);
1135 /* put the cursor at the top */
1136 if (!(format
& SFF_SELECTION
))
1137 SendMessageA(editor
->hWnd
, EM_SETSEL
, 0, 0);
1140 /* Restore saved undo mode */
1141 editor
->nUndoMode
= nUndoMode
;
1143 /* even if we didn't add an undo, we need to commit anything on the stack */
1144 ME_CommitUndo(editor
);
1146 /* If SFF_SELECTION isn't set, delete any undos from before we started too */
1147 if (!(format
& SFF_SELECTION
))
1148 ME_EmptyUndoStack(editor
);
1150 ME_ReleaseStyle(style
);
1151 editor
->nEventMask
= nEventMask
;
1152 ME_UpdateRepaint(editor
);
1153 if (!(format
& SFF_SELECTION
)) {
1154 ME_ClearTempStyle(editor
);
1156 HideCaret(editor
->hWnd
);
1157 ME_MoveCaret(editor
);
1158 ShowCaret(editor
->hWnd
);
1159 ME_SendSelChange(editor
);
1160 ME_SendRequestResize(editor
, FALSE
);
1166 typedef struct tagME_RTFStringStreamStruct
1171 } ME_RTFStringStreamStruct
;
1173 static DWORD CALLBACK
ME_ReadFromRTFString(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
1175 ME_RTFStringStreamStruct
*pStruct
= (ME_RTFStringStreamStruct
*)dwCookie
;
1178 count
= min(cb
, pStruct
->length
- pStruct
->pos
);
1179 memmove(lpBuff
, pStruct
->string
+ pStruct
->pos
, count
);
1180 pStruct
->pos
+= count
;
1186 ME_StreamInRTFString(ME_TextEditor
*editor
, BOOL selection
, char *string
)
1189 ME_RTFStringStreamStruct data
;
1191 data
.string
= string
;
1192 data
.length
= strlen(string
);
1194 es
.dwCookie
= (DWORD
)&data
;
1195 es
.pfnCallback
= ME_ReadFromRTFString
;
1196 ME_StreamIn(editor
, SF_RTF
| (selection
? SFF_SELECTION
: 0), &es
, FALSE
);
1201 ME_FindItemAtOffset(ME_TextEditor
*editor
, ME_DIType nItemType
, int nOffset
, int *nItemOffset
)
1203 ME_DisplayItem
*item
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
1206 while (item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= nOffset
)
1207 item
= ME_FindItemFwd(item
, diParagraph
);
1212 nOffset
-= item
->member
.para
.nCharOfs
;
1213 if (nItemType
== diParagraph
) {
1215 *nItemOffset
= nOffset
;
1220 item
= ME_FindItemFwd(item
, diRun
);
1221 runLength
= ME_StrLen(item
->member
.run
.strText
);
1222 if (item
->member
.run
.nFlags
& MERF_ENDPARA
)
1223 runLength
= item
->member
.run
.nCR
+ item
->member
.run
.nLF
;
1224 } while (item
&& (item
->member
.run
.nCharOfs
+ runLength
<= nOffset
));
1226 nOffset
-= item
->member
.run
.nCharOfs
;
1228 /* Special case: nOffset may not point exactly at the division between the
1229 \r and the \n in 1.0 emulation. If such a case happens, it is sent
1230 into the next run, if one exists
1232 if ( item
->member
.run
.nFlags
& MERF_ENDPARA
1233 && nOffset
== item
->member
.run
.nCR
1234 && item
->member
.run
.nLF
> 0) {
1235 ME_DisplayItem
*nextItem
;
1236 nextItem
= ME_FindItemFwd(item
, diRun
);
1243 *nItemOffset
= nOffset
;
1250 ME_FindText(ME_TextEditor
*editor
, DWORD flags
, const CHARRANGE
*chrg
, const WCHAR
*text
, CHARRANGE
*chrgText
)
1252 const int nLen
= lstrlenW(text
);
1253 const int nTextLen
= ME_GetTextLength(editor
);
1256 ME_DisplayItem
*item
;
1257 ME_DisplayItem
*para
;
1258 WCHAR wLastChar
= ' ';
1260 TRACE("flags==0x%08x, chrg->cpMin==%d, chrg->cpMax==%d text==%s\n",
1261 flags
, chrg
->cpMin
, chrg
->cpMax
, debugstr_w(text
));
1263 if (flags
& ~(FR_DOWN
| FR_MATCHCASE
| FR_WHOLEWORD
))
1264 FIXME("Flags 0x%08x not implemented\n",
1265 flags
& ~(FR_DOWN
| FR_MATCHCASE
| FR_WHOLEWORD
));
1268 if (chrg
->cpMax
== -1)
1271 nMax
= chrg
->cpMax
> nTextLen
? nTextLen
: chrg
->cpMax
;
1273 /* In 1.0 emulation, if cpMax reaches end of text, add the FR_DOWN flag */
1274 if (editor
->bEmulateVersion10
&& nMax
== nTextLen
)
1279 /* In 1.0 emulation, cpMin must always be no greater than cpMax */
1280 if (editor
->bEmulateVersion10
&& nMax
< nMin
)
1284 chrgText
->cpMin
= -1;
1285 chrgText
->cpMax
= -1;
1290 /* when searching up, if cpMin < cpMax, then instead of searching
1291 * on [cpMin,cpMax], we search on [0,cpMin], otherwise, search on
1292 * [cpMax, cpMin]. The exception is when cpMax is -1, in which
1293 * case, it is always bigger than cpMin.
1295 if (!editor
->bEmulateVersion10
&& !(flags
& FR_DOWN
))
1299 nMax
= nMin
> nTextLen
? nTextLen
: nMin
;
1300 if (nMin
< nSwap
|| chrg
->cpMax
== -1)
1306 if (!nLen
|| nMin
< 0 || nMax
< 0 || nMax
< nMin
)
1309 chrgText
->cpMin
= chrgText
->cpMax
= -1;
1313 if (flags
& FR_DOWN
) /* Forward search */
1315 /* If possible, find the character before where the search starts */
1316 if ((flags
& FR_WHOLEWORD
) && nMin
)
1319 item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
1323 chrgText
->cpMin
= chrgText
->cpMax
= -1;
1326 wLastChar
= item
->member
.run
.strText
->szData
[nStart
];
1330 item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
1334 chrgText
->cpMin
= chrgText
->cpMax
= -1;
1338 para
= ME_GetParagraph(item
);
1340 && para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
+ nLen
<= nMax
)
1342 ME_DisplayItem
*pCurItem
= item
;
1343 int nCurStart
= nStart
;
1346 while (pCurItem
&& ME_CharCompare(pCurItem
->member
.run
.strText
->szData
[nCurStart
+ nMatched
], text
[nMatched
], (flags
& FR_MATCHCASE
)))
1348 if ((flags
& FR_WHOLEWORD
) && isalnumW(wLastChar
))
1352 if (nMatched
== nLen
)
1354 ME_DisplayItem
*pNextItem
= pCurItem
;
1355 int nNextStart
= nCurStart
;
1358 /* Check to see if next character is a whitespace */
1359 if (flags
& FR_WHOLEWORD
)
1361 if (nCurStart
+ nMatched
== ME_StrLen(pCurItem
->member
.run
.strText
))
1363 pNextItem
= ME_FindItemFwd(pCurItem
, diRun
);
1364 nNextStart
= -nMatched
;
1368 wNextChar
= pNextItem
->member
.run
.strText
->szData
[nNextStart
+ nMatched
];
1372 if (isalnumW(wNextChar
))
1376 nStart
+= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
;
1379 chrgText
->cpMin
= nStart
;
1380 chrgText
->cpMax
= nStart
+ nLen
;
1382 TRACE("found at %d-%d\n", nStart
, nStart
+ nLen
);
1385 if (nCurStart
+ nMatched
== ME_StrLen(pCurItem
->member
.run
.strText
))
1387 pCurItem
= ME_FindItemFwd(pCurItem
, diRun
);
1388 para
= ME_GetParagraph(pCurItem
);
1389 nCurStart
= -nMatched
;
1393 wLastChar
= pCurItem
->member
.run
.strText
->szData
[nCurStart
+ nMatched
];
1398 if (nStart
== ME_StrLen(item
->member
.run
.strText
))
1400 item
= ME_FindItemFwd(item
, diRun
);
1401 para
= ME_GetParagraph(item
);
1406 else /* Backward search */
1408 /* If possible, find the character after where the search ends */
1409 if ((flags
& FR_WHOLEWORD
) && nMax
< nTextLen
- 1)
1412 item
= ME_FindItemAtOffset(editor
, diRun
, nEnd
, &nEnd
);
1416 chrgText
->cpMin
= chrgText
->cpMax
= -1;
1419 wLastChar
= item
->member
.run
.strText
->szData
[nEnd
];
1423 item
= ME_FindItemAtOffset(editor
, diRun
, nEnd
, &nEnd
);
1427 chrgText
->cpMin
= chrgText
->cpMax
= -1;
1431 para
= ME_GetParagraph(item
);
1434 && para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nEnd
- nLen
>= nMin
)
1436 ME_DisplayItem
*pCurItem
= item
;
1440 if (nCurEnd
- nMatched
== 0)
1442 pCurItem
= ME_FindItemBack(pCurItem
, diRun
);
1443 para
= ME_GetParagraph(pCurItem
);
1444 nCurEnd
= ME_StrLen(pCurItem
->member
.run
.strText
) + nMatched
;
1447 while (pCurItem
&& ME_CharCompare(pCurItem
->member
.run
.strText
->szData
[nCurEnd
- nMatched
- 1], text
[nLen
- nMatched
- 1], (flags
& FR_MATCHCASE
)))
1449 if ((flags
& FR_WHOLEWORD
) && isalnumW(wLastChar
))
1453 if (nMatched
== nLen
)
1455 ME_DisplayItem
*pPrevItem
= pCurItem
;
1456 int nPrevEnd
= nCurEnd
;
1459 /* Check to see if previous character is a whitespace */
1460 if (flags
& FR_WHOLEWORD
)
1462 if (nPrevEnd
- nMatched
== 0)
1464 pPrevItem
= ME_FindItemBack(pCurItem
, diRun
);
1466 nPrevEnd
= ME_StrLen(pPrevItem
->member
.run
.strText
) + nMatched
;
1470 wPrevChar
= pPrevItem
->member
.run
.strText
->szData
[nPrevEnd
- nMatched
- 1];
1474 if (isalnumW(wPrevChar
))
1478 nStart
= para
->member
.para
.nCharOfs
+ pCurItem
->member
.run
.nCharOfs
+ nCurEnd
- nMatched
;
1481 chrgText
->cpMin
= nStart
;
1482 chrgText
->cpMax
= nStart
+ nLen
;
1484 TRACE("found at %d-%d\n", nStart
, nStart
+ nLen
);
1487 if (nCurEnd
- nMatched
== 0)
1489 pCurItem
= ME_FindItemBack(pCurItem
, diRun
);
1490 /* Don't care about pCurItem becoming NULL here; it's already taken
1491 * care of in the exterior loop condition */
1492 para
= ME_GetParagraph(pCurItem
);
1493 nCurEnd
= ME_StrLen(pCurItem
->member
.run
.strText
) + nMatched
;
1497 wLastChar
= pCurItem
->member
.run
.strText
->szData
[nCurEnd
- nMatched
- 1];
1504 item
= ME_FindItemBack(item
, diRun
);
1505 para
= ME_GetParagraph(item
);
1506 nEnd
= ME_StrLen(item
->member
.run
.strText
);
1510 TRACE("not found\n");
1512 chrgText
->cpMin
= chrgText
->cpMax
= -1;
1516 /* helper to send a msg filter notification */
1518 ME_FilterEvent(ME_TextEditor
*editor
, UINT msg
, WPARAM
* wParam
, LPARAM
* lParam
)
1522 msgf
.nmhdr
.hwndFrom
= editor
->hWnd
;
1523 msgf
.nmhdr
.idFrom
= GetWindowLongW(editor
->hWnd
, GWLP_ID
);
1524 msgf
.nmhdr
.code
= EN_MSGFILTER
;
1527 msgf
.wParam
= *wParam
;
1528 msgf
.lParam
= *lParam
;
1529 if (SendMessageW(GetParent(editor
->hWnd
), WM_NOTIFY
, msgf
.nmhdr
.idFrom
, (LPARAM
)&msgf
))
1531 *wParam
= msgf
.wParam
;
1532 *lParam
= msgf
.lParam
;
1533 msgf
.wParam
= *wParam
;
1539 ME_KeyDown(ME_TextEditor
*editor
, WORD nKey
)
1541 BOOL ctrl_is_down
= GetKeyState(VK_CONTROL
) & 0x8000;
1542 BOOL shift_is_down
= GetKeyState(VK_SHIFT
) & 0x8000;
1544 if (nKey
!= VK_SHIFT
&& nKey
!= VK_CONTROL
&& nKey
!= VK_MENU
)
1545 editor
->nSelectionType
= stPosition
;
1553 editor
->nUDArrowX
= -1;
1559 ME_CommitUndo(editor
); /* End coalesced undos for typed characters */
1560 ME_ArrowKey(editor
, nKey
, shift_is_down
, ctrl_is_down
);
1564 editor
->nUDArrowX
= -1;
1565 /* FIXME backspace and delete aren't the same, they act different wrt paragraph style of the merged paragraph */
1566 if (GetWindowLongW(editor
->hWnd
, GWL_STYLE
) & ES_READONLY
)
1568 if (ME_IsSelection(editor
))
1570 ME_DeleteSelection(editor
);
1571 ME_CommitUndo(editor
);
1573 else if (nKey
== VK_DELETE
)
1575 /* Delete stops group typing.
1576 * (See MSDN remarks on EM_STOPGROUPTYPING message) */
1577 ME_DeleteTextAtCursor(editor
, 1, 1);
1578 ME_CommitUndo(editor
);
1580 else if (ME_ArrowKey(editor
, VK_LEFT
, FALSE
, FALSE
))
1582 /* Backspace can be grouped for a single undo */
1583 ME_ContinueCoalescingTransaction(editor
);
1584 ME_DeleteTextAtCursor(editor
, 1, 1);
1585 ME_CommitCoalescingUndo(editor
);
1589 ME_UpdateSelectionLinkAttribute(editor
);
1590 ME_UpdateRepaint(editor
);
1591 ME_SendRequestResize(editor
, FALSE
);
1595 if (nKey
!= VK_SHIFT
&& nKey
!= VK_CONTROL
&& nKey
&& nKey
!= VK_MENU
)
1596 editor
->nUDArrowX
= -1;
1603 chf
.cbSize
= sizeof(chf
);
1605 ME_GetSelectionCharFormat(editor
, &chf
);
1606 ME_DumpStyleToBuf(&chf
, buf
);
1607 MessageBoxA(NULL
, buf
, "Style dump", MB_OK
);
1611 ME_CheckCharOffsets(editor
);
1618 /* Process the message and calculate the new click count.
1620 * returns: The click count if it is mouse down event, else returns 0. */
1621 static int ME_CalculateClickCount(HWND hWnd
, UINT msg
, WPARAM wParam
,
1624 static int clickNum
= 0;
1625 if (msg
< WM_MOUSEFIRST
|| msg
> WM_MOUSELAST
)
1628 if ((msg
== WM_LBUTTONDBLCLK
) ||
1629 (msg
== WM_RBUTTONDBLCLK
) ||
1630 (msg
== WM_MBUTTONDBLCLK
) ||
1631 (msg
== WM_XBUTTONDBLCLK
))
1633 msg
-= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
1636 if ((msg
== WM_LBUTTONDOWN
) ||
1637 (msg
== WM_RBUTTONDOWN
) ||
1638 (msg
== WM_MBUTTONDOWN
) ||
1639 (msg
== WM_XBUTTONDOWN
))
1641 static MSG prevClickMsg
;
1643 clickMsg
.hwnd
= hWnd
;
1644 clickMsg
.message
= msg
;
1645 clickMsg
.wParam
= wParam
;
1646 clickMsg
.lParam
= lParam
;
1647 clickMsg
.time
= GetMessageTime();
1648 clickMsg
.pt
.x
= (short)LOWORD(lParam
);
1649 clickMsg
.pt
.y
= (short)HIWORD(lParam
);
1650 if ((clickNum
!= 0) &&
1651 (clickMsg
.message
== prevClickMsg
.message
) &&
1652 (clickMsg
.hwnd
== prevClickMsg
.hwnd
) &&
1653 (clickMsg
.wParam
== prevClickMsg
.wParam
) &&
1654 (clickMsg
.time
- prevClickMsg
.time
< GetDoubleClickTime()) &&
1655 (abs(clickMsg
.pt
.x
- prevClickMsg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
1656 (abs(clickMsg
.pt
.y
- prevClickMsg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
1662 prevClickMsg
= clickMsg
;
1669 static BOOL
ME_SetCursor(ME_TextEditor
*editor
)
1674 DWORD messagePos
= GetMessagePos();
1675 pt
.x
= (short)LOWORD(messagePos
);
1676 pt
.y
= (short)HIWORD(messagePos
);
1677 ScreenToClient(editor
->hWnd
, &pt
);
1678 if ((GetWindowLongW(editor
->hWnd
, GWL_STYLE
) & ES_SELECTIONBAR
) &&
1679 (pt
.x
< editor
->selofs
||
1680 (editor
->nSelectionType
== stLine
&& GetCapture() == editor
->hWnd
)))
1685 offset
= ME_CharFromPos(editor
, pt
.x
, pt
.y
, &isExact
);
1688 if (editor
->AutoURLDetect_bEnable
)
1692 ME_CursorFromCharOfs(editor
, offset
, &cursor
);
1693 run
= &cursor
.pRun
->member
.run
;
1694 if (editor
->AutoURLDetect_bEnable
&&
1695 run
->style
->fmt
.dwMask
& CFM_LINK
&&
1696 run
->style
->fmt
.dwEffects
& CFE_LINK
)
1698 SetCursor(LoadCursorW(NULL
, (WCHAR
*)IDC_HAND
));
1702 if (ME_IsSelection(editor
))
1704 int selStart
, selEnd
;
1705 ME_GetSelection(editor
, &selStart
, &selEnd
);
1706 if (selStart
<= offset
&& selEnd
>= offset
) {
1707 SetCursor(LoadCursorW(NULL
, (WCHAR
*)IDC_ARROW
));
1712 SetCursor(LoadCursorW(NULL
, (WCHAR
*)IDC_IBEAM
));
1716 static BOOL
ME_ShowContextMenu(ME_TextEditor
*editor
, int x
, int y
)
1721 if(!editor
->lpOleCallback
)
1723 ME_GetSelection(editor
, &selrange
.cpMin
, &selrange
.cpMax
);
1724 if(selrange
.cpMin
== selrange
.cpMax
)
1725 seltype
|= SEL_EMPTY
;
1728 /* FIXME: Handle objects */
1729 seltype
|= SEL_TEXT
;
1730 if(selrange
.cpMax
-selrange
.cpMin
> 1)
1731 seltype
|= SEL_MULTICHAR
;
1733 if(SUCCEEDED(IRichEditOleCallback_GetContextMenu(editor
->lpOleCallback
, seltype
, NULL
, &selrange
, &menu
)))
1735 TrackPopupMenu(menu
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, GetParent(editor
->hWnd
), NULL
);
1741 ME_TextEditor
*ME_MakeEditor(HWND hWnd
) {
1742 ME_TextEditor
*ed
= ALLOC_OBJ(ME_TextEditor
);
1745 ed
->bEmulateVersion10
= FALSE
;
1746 ed
->pBuffer
= ME_MakeText();
1747 ed
->nZoomNumerator
= ed
->nZoomDenominator
= 0;
1748 ME_MakeFirstParagraph(ed
);
1749 /* The four cursors are for:
1750 * 0 - The position where the caret is shown
1751 * 1 - The anchored end of the selection (for normal selection)
1752 * 2 & 3 - The anchored start and end respectively for word, line,
1753 * or paragraph selection.
1756 ed
->pCursors
= ALLOC_N_OBJ(ME_Cursor
, ed
->nCursors
);
1757 ed
->pCursors
[0].pRun
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diRun
);
1758 ed
->pCursors
[0].nOffset
= 0;
1759 ed
->pCursors
[1].pRun
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diRun
);
1760 ed
->pCursors
[1].nOffset
= 0;
1761 ed
->pCursors
[2] = ed
->pCursors
[0];
1762 ed
->pCursors
[3] = ed
->pCursors
[1];
1763 ed
->nLastTotalLength
= ed
->nTotalLength
= 0;
1767 ed
->rgbBackColor
= -1;
1768 ed
->hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
1769 ed
->bCaretAtEnd
= FALSE
;
1771 ed
->nModifyStep
= 0;
1772 ed
->nTextLimit
= TEXT_LIMIT_DEFAULT
;
1773 ed
->pUndoStack
= ed
->pRedoStack
= ed
->pUndoStackBottom
= NULL
;
1774 ed
->nUndoStackSize
= 0;
1775 ed
->nUndoLimit
= STACK_SIZE_DEFAULT
;
1776 ed
->nUndoMode
= umAddToUndo
;
1777 ed
->nParagraphs
= 1;
1778 ed
->nLastSelStart
= ed
->nLastSelEnd
= 0;
1779 ed
->pLastSelStartPara
= ed
->pLastSelEndPara
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diParagraph
);
1781 ed
->bWordWrap
= (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_HSCROLL
) ? FALSE
: TRUE
;
1782 ed
->bHideSelection
= FALSE
;
1783 ed
->nInvalidOfs
= -1;
1784 ed
->pfnWordBreak
= NULL
;
1785 ed
->lpOleCallback
= NULL
;
1786 ed
->mode
= TM_RICHTEXT
| TM_MULTILEVELUNDO
| TM_MULTICODEPAGE
;
1787 ed
->AutoURLDetect_bEnable
= FALSE
;
1788 ed
->bHaveFocus
= FALSE
;
1789 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
1791 ed
->pFontCache
[i
].nRefs
= 0;
1792 ed
->pFontCache
[i
].nAge
= 0;
1793 ed
->pFontCache
[i
].hFont
= NULL
;
1796 ME_CheckCharOffsets(ed
);
1797 if (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_SELECTIONBAR
)
1798 ed
->selofs
= SELECTIONBAR_WIDTH
;
1801 ed
->nSelectionType
= stPosition
;
1803 if (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_PASSWORD
)
1804 ed
->cPasswordMask
= '*';
1806 ed
->cPasswordMask
= 0;
1808 ed
->notified_cr
.cpMin
= ed
->notified_cr
.cpMax
= 0;
1810 /* Default vertical scrollbar information */
1811 ed
->vert_si
.cbSize
= sizeof(SCROLLINFO
);
1812 ed
->vert_si
.nMin
= 0;
1813 ed
->vert_si
.nMax
= 0;
1814 ed
->vert_si
.nPage
= 0;
1815 ed
->vert_si
.nPos
= 0;
1817 OleInitialize(NULL
);
1822 typedef struct tagME_GlobalDestStruct
1826 } ME_GlobalDestStruct
;
1828 static DWORD CALLBACK
ME_ReadFromHGLOBALUnicode(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
1830 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
1835 pDest
= (WORD
*)lpBuff
;
1836 pSrc
= (WORD
*)GlobalLock(pData
->hData
);
1837 for (i
= 0; i
<cb
&& pSrc
[pData
->nLength
+i
]; i
++) {
1838 pDest
[i
] = pSrc
[pData
->nLength
+i
];
1840 pData
->nLength
+= i
;
1842 GlobalUnlock(pData
->hData
);
1846 static DWORD CALLBACK
ME_ReadFromHGLOBALRTF(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
1848 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
1853 pSrc
= (BYTE
*)GlobalLock(pData
->hData
);
1854 for (i
= 0; i
<cb
&& pSrc
[pData
->nLength
+i
]; i
++) {
1855 pDest
[i
] = pSrc
[pData
->nLength
+i
];
1857 pData
->nLength
+= i
;
1859 GlobalUnlock(pData
->hData
);
1864 void ME_DestroyEditor(ME_TextEditor
*editor
)
1866 ME_DisplayItem
*pFirst
= editor
->pBuffer
->pFirst
;
1867 ME_DisplayItem
*p
= pFirst
, *pNext
= NULL
;
1870 ME_ClearTempStyle(editor
);
1871 ME_EmptyUndoStack(editor
);
1874 ME_DestroyDisplayItem(p
);
1877 ME_ReleaseStyle(editor
->pBuffer
->pDefaultStyle
);
1878 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
1880 if (editor
->pFontCache
[i
].hFont
)
1881 DeleteObject(editor
->pFontCache
[i
].hFont
);
1883 if (editor
->rgbBackColor
!= -1)
1884 DeleteObject(editor
->hbrBackground
);
1885 if(editor
->lpOleCallback
)
1886 IUnknown_Release(editor
->lpOleCallback
);
1889 FREE_OBJ(editor
->pBuffer
);
1890 FREE_OBJ(editor
->pCursors
);
1895 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
1900 case DLL_PROCESS_ATTACH
:
1901 DisableThreadLibraryCalls(hinstDLL
);
1902 me_heap
= HeapCreate (0, 0x10000, 0);
1903 if (!ME_RegisterEditorClass(hinstDLL
)) return FALSE
;
1904 hLeft
= LoadCursorW(hinstDLL
, MAKEINTRESOURCEW(OCR_REVERSE
));
1908 case DLL_PROCESS_DETACH
:
1909 UnregisterClassW(RichEdit20W
, 0);
1910 UnregisterClassW(RichEdit50W
, 0);
1911 UnregisterClassA("RichEdit20A", 0);
1912 UnregisterClassA("RichEdit50A", 0);
1913 if (ME_ListBoxRegistered
)
1914 UnregisterClassW(REListBox20W
, 0);
1915 if (ME_ComboBoxRegistered
)
1916 UnregisterClassW(REComboBox20W
, 0);
1918 HeapDestroy (me_heap
);
1926 #define UNSUPPORTED_MSG(e) \
1928 FIXME(#e ": stub\n"); \
1929 return DefWindowProcW(hWnd, msg, wParam, lParam);
1931 static const char * const edit_messages
[] = {
1960 "EM_SETPASSWORDCHAR",
1961 "EM_EMPTYUNDOBUFFER",
1962 "EM_GETFIRSTVISIBLELINE",
1964 "EM_SETWORDBREAKPROC",
1965 "EM_GETWORDBREAKPROC",
1966 "EM_GETPASSWORDCHAR",
1974 static const char * const richedit_messages
[] = {
1979 "EM_EXLINEFROMCHAR",
1985 "EM_GETOLEINTERFACE",
1995 "EM_SETOLECALLBACK",
1997 "EM_SETTARGETDEVICE",
2005 "EM_GETWORDBREAKPROCEX",
2006 "EM_SETWORDBREAKPROCEX",
2008 "EM_UNKNOWN_USER_83",
2013 "EM_STOPGROUPTYPING",
2017 "EM_GETAUTOURLDETECT",
2020 "EM_GETTEXTLENGTHEX",
2023 "EM_UNKNOWN_USER_98",
2024 "EM_UNKNOWN_USER_99",
2025 "EM_SETPUNCTUATION",
2026 "EM_GETPUNCTUATION",
2027 "EM_SETWORDWRAPMODE",
2028 "EM_GETWORDWRAPMODE",
2034 "EM_UNKNOWN_USER_109",
2035 "EM_UNKNOWN_USER_110",
2036 "EM_UNKNOWN_USER_111",
2037 "EM_UNKNOWN_USER_112",
2038 "EM_UNKNOWN_USER_113",
2039 "EM_UNKNOWN_USER_114",
2040 "EM_UNKNOWN_USER_115",
2041 "EM_UNKNOWN_USER_116",
2042 "EM_UNKNOWN_USER_117",
2043 "EM_UNKNOWN_USER_118",
2044 "EM_UNKNOWN_USER_119",
2045 "EM_SETLANGOPTIONS",
2046 "EM_GETLANGOPTIONS",
2047 "EM_GETIMECOMPMODE",
2051 "EM_SETIMEMODEBIAS",
2056 get_msg_name(UINT msg
)
2058 if (msg
>= EM_GETSEL
&& msg
<= EM_CHARFROMPOS
)
2059 return edit_messages
[msg
- EM_GETSEL
];
2060 if (msg
>= EM_CANPASTE
&& msg
<= EM_GETIMEMODEBIAS
)
2061 return richedit_messages
[msg
- EM_CANPASTE
];
2065 static LRESULT
RichEditWndProc_common(HWND hWnd
, UINT msg
, WPARAM wParam
,
2066 LPARAM lParam
, BOOL unicode
)
2068 ME_TextEditor
*editor
= (ME_TextEditor
*)GetWindowLongPtrW(hWnd
, 0);
2070 TRACE("hwnd %p msg %04x (%s) %lx %lx, unicode %d\n",
2071 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
, unicode
);
2073 if (!editor
&& msg
!= WM_NCCREATE
&& msg
!= WM_NCDESTROY
) {
2074 ERR("called with invalid hWnd %p - application bug?\n", hWnd
);
2080 UNSUPPORTED_MSG(EM_DISPLAYBAND
)
2081 UNSUPPORTED_MSG(EM_FINDWORDBREAK
)
2082 UNSUPPORTED_MSG(EM_FMTLINES
)
2083 UNSUPPORTED_MSG(EM_FORMATRANGE
)
2084 UNSUPPORTED_MSG(EM_GETBIDIOPTIONS
)
2085 UNSUPPORTED_MSG(EM_GETEDITSTYLE
)
2086 UNSUPPORTED_MSG(EM_GETIMECOMPMODE
)
2087 /* UNSUPPORTED_MSG(EM_GETIMESTATUS) missing in Wine headers */
2088 UNSUPPORTED_MSG(EM_GETLANGOPTIONS
)
2089 /* UNSUPPORTED_MSG(EM_GETOLEINTERFACE) separate stub */
2090 UNSUPPORTED_MSG(EM_GETREDONAME
)
2091 UNSUPPORTED_MSG(EM_GETTEXTMODE
)
2092 UNSUPPORTED_MSG(EM_GETTYPOGRAPHYOPTIONS
)
2093 UNSUPPORTED_MSG(EM_GETUNDONAME
)
2094 UNSUPPORTED_MSG(EM_GETWORDBREAKPROCEX
)
2095 UNSUPPORTED_MSG(EM_PASTESPECIAL
)
2096 UNSUPPORTED_MSG(EM_SELECTIONTYPE
)
2097 UNSUPPORTED_MSG(EM_SETBIDIOPTIONS
)
2098 UNSUPPORTED_MSG(EM_SETEDITSTYLE
)
2099 UNSUPPORTED_MSG(EM_SETFONTSIZE
)
2100 UNSUPPORTED_MSG(EM_SETLANGOPTIONS
)
2101 UNSUPPORTED_MSG(EM_SETPALETTE
)
2102 UNSUPPORTED_MSG(EM_SETTABSTOPS
)
2103 UNSUPPORTED_MSG(EM_SETTYPOGRAPHYOPTIONS
)
2104 UNSUPPORTED_MSG(EM_SETWORDBREAKPROCEX
)
2105 UNSUPPORTED_MSG(WM_STYLECHANGING
)
2106 UNSUPPORTED_MSG(WM_STYLECHANGED
)
2108 /* Messages specific to Richedit controls */
2111 return ME_StreamIn(editor
, wParam
, (EDITSTREAM
*)lParam
, TRUE
);
2113 return ME_StreamOut(editor
, wParam
, (EDITSTREAM
*)lParam
);
2116 UINT code
= DLGC_WANTCHARS
|DLGC_WANTARROWS
;
2117 if(lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
2119 int vk
= (int)((LPMSG
)lParam
)->wParam
;
2120 /* if style says we want return key */
2121 if((vk
== VK_RETURN
) && (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_WANTRETURN
))
2123 code
|= DLGC_WANTMESSAGE
;
2125 /* we always handle ctrl-tab */
2126 if((vk
== VK_TAB
) && (GetKeyState(VK_CONTROL
) & 0x8000))
2128 code
|= DLGC_WANTMESSAGE
;
2135 CREATESTRUCTW
*pcs
= (CREATESTRUCTW
*)lParam
;
2136 TRACE("WM_NCCREATE: style 0x%08x\n", pcs
->style
);
2137 editor
= ME_MakeEditor(hWnd
);
2138 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)editor
);
2141 case EM_EMPTYUNDOBUFFER
:
2142 ME_EmptyUndoStack(editor
);
2146 /* Note: wParam/lParam can be NULL */
2148 PUINT pfrom
= wParam
? (PUINT
)wParam
: &from
;
2149 PUINT pto
= lParam
? (PUINT
)lParam
: &to
;
2150 ME_GetSelection(editor
, (int *)pfrom
, (int *)pto
);
2151 if ((*pfrom
|*pto
) & 0xFFFF0000)
2153 return MAKELONG(*pfrom
,*pto
);
2157 CHARRANGE
*pRange
= (CHARRANGE
*)lParam
;
2158 ME_GetSelection(editor
, &pRange
->cpMin
, &pRange
->cpMax
);
2159 TRACE("EM_EXGETSEL = (%d,%d)\n", pRange
->cpMin
, pRange
->cpMax
);
2162 case EM_SETUNDOLIMIT
:
2164 if ((int)wParam
< 0)
2165 editor
->nUndoLimit
= STACK_SIZE_DEFAULT
;
2167 editor
->nUndoLimit
= min(wParam
, STACK_SIZE_MAX
);
2168 /* Setting a max stack size keeps wine from getting killed
2169 for hogging memory. Windows allocates all this memory at once, so
2170 no program would realistically set a value above our maximum. */
2171 return editor
->nUndoLimit
;
2174 return editor
->pUndoStack
!= NULL
;
2176 return editor
->pRedoStack
!= NULL
;
2177 case WM_UNDO
: /* FIXME: actually not the same */
2179 return ME_Undo(editor
);
2181 return ME_Redo(editor
);
2184 /* these flags are equivalent to the ES_* counterparts */
2185 DWORD mask
= ECO_VERTICAL
| ECO_AUTOHSCROLL
| ECO_AUTOVSCROLL
|
2186 ECO_NOHIDESEL
| ECO_READONLY
| ECO_WANTRETURN
;
2187 DWORD settings
= GetWindowLongW(hWnd
, GWL_STYLE
) & mask
;
2193 /* these flags are equivalent to ES_* counterparts
2194 * ECO_READONLY is already implemented in the code, only requires
2195 * setting the bit to work
2197 DWORD mask
= ECO_VERTICAL
| ECO_AUTOHSCROLL
| ECO_AUTOVSCROLL
|
2198 ECO_NOHIDESEL
| ECO_READONLY
| ECO_WANTRETURN
| ECO_SELECTIONBAR
;
2199 DWORD raw
= GetWindowLongW(hWnd
, GWL_STYLE
);
2200 DWORD settings
= mask
& raw
;
2216 SetWindowLongW(hWnd
, GWL_STYLE
, (raw
& ~mask
) | (settings
& mask
));
2218 if (settings
& ECO_AUTOWORDSELECTION
)
2219 FIXME("ECO_AUTOWORDSELECTION not implemented yet!\n");
2220 if (settings
& ECO_SELECTIONBAR
)
2221 editor
->selofs
= SELECTIONBAR_WIDTH
;
2224 ME_WrapMarkedParagraphs(editor
);
2226 if (settings
& ECO_VERTICAL
)
2227 FIXME("ECO_VERTICAL not implemented yet!\n");
2228 if (settings
& ECO_AUTOHSCROLL
)
2229 FIXME("ECO_AUTOHSCROLL not implemented yet!\n");
2230 if (settings
& ECO_AUTOVSCROLL
)
2231 FIXME("ECO_AUTOVSCROLL not implemented yet!\n");
2232 if (settings
& ECO_NOHIDESEL
)
2233 FIXME("ECO_NOHIDESEL not implemented yet!\n");
2234 if (settings
& ECO_WANTRETURN
)
2235 FIXME("ECO_WANTRETURN not implemented yet!\n");
2241 ME_InvalidateSelection(editor
);
2242 ME_SetSelection(editor
, wParam
, lParam
);
2243 ME_InvalidateSelection(editor
);
2244 HideCaret(editor
->hWnd
);
2245 ME_ShowCaret(editor
);
2246 ME_SendSelChange(editor
);
2249 case EM_SETSCROLLPOS
:
2251 POINT
*point
= (POINT
*)lParam
;
2252 ME_ScrollAbs(editor
, point
->y
);
2255 case EM_AUTOURLDETECT
:
2257 if (wParam
==1 || wParam
==0)
2259 editor
->AutoURLDetect_bEnable
= (BOOL
)wParam
;
2262 return E_INVALIDARG
;
2264 case EM_GETAUTOURLDETECT
:
2266 return editor
->AutoURLDetect_bEnable
;
2271 CHARRANGE range
= *(CHARRANGE
*)lParam
;
2273 TRACE("EM_EXSETSEL (%d,%d)\n", range
.cpMin
, range
.cpMax
);
2275 ME_InvalidateSelection(editor
);
2276 end
= ME_SetSelection(editor
, range
.cpMin
, range
.cpMax
);
2277 ME_InvalidateSelection(editor
);
2278 HideCaret(editor
->hWnd
);
2279 ME_ShowCaret(editor
);
2280 ME_SendSelChange(editor
);
2284 case EM_SHOWSCROLLBAR
:
2286 ShowScrollBar(editor
->hWnd
, wParam
, lParam
);
2292 SETTEXTEX
*pStruct
= (SETTEXTEX
*)wParam
;
2296 int oldModify
= editor
->nModifyStep
;
2298 if (!pStruct
) return 0;
2300 TRACE("EM_SETTEXTEX - %s, flags %d, cp %d\n",
2301 pStruct
->codepage
== 1200 ? debugstr_w((LPCWSTR
)lParam
) : debugstr_a((LPCSTR
)lParam
),
2302 pStruct
->flags
, pStruct
->codepage
);
2304 /* FIXME: make use of pStruct->codepage in the to unicode translation */
2305 wszText
= lParam
? ME_ToUnicode(pStruct
->codepage
== 1200, (void *)lParam
) : NULL
;
2306 len
= wszText
? lstrlenW(wszText
) : 0;
2308 if (pStruct
->flags
& ST_SELECTION
) {
2309 ME_GetSelection(editor
, &from
, &to
);
2310 style
= ME_GetSelectionInsertStyle(editor
);
2311 ME_InternalDeleteText(editor
, from
, to
- from
);
2312 if (pStruct
->codepage
!= 1200 && lParam
&& !strncmp((char *)lParam
, "{\\rtf", 5))
2313 ME_StreamInRTFString(editor
, 1, (char *)lParam
);
2314 else ME_InsertTextFromCursor(editor
, 0, wszText
, len
, style
);
2315 ME_ReleaseStyle(style
);
2317 if (editor
->AutoURLDetect_bEnable
) ME_UpdateSelectionLinkAttribute(editor
);
2320 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
));
2321 if (pStruct
->codepage
!= 1200 && lParam
&& !strncmp((char *)lParam
, "{\\rtf", 5))
2322 ME_StreamInRTFString(editor
, 0, (char *)lParam
);
2323 else ME_InsertTextFromCursor(editor
, 0, wszText
, len
, editor
->pBuffer
->pDefaultStyle
);
2326 if (editor
->AutoURLDetect_bEnable
) ME_UpdateLinkAttribute(editor
, 0, -1);
2328 ME_CommitUndo(editor
);
2329 if (!(pStruct
->flags
& ST_KEEPUNDO
))
2331 editor
->nModifyStep
= oldModify
;
2332 ME_EmptyUndoStack(editor
);
2334 ME_UpdateRepaint(editor
);
2337 case EM_SETBKGNDCOLOR
:
2340 if (editor
->rgbBackColor
!= -1) {
2341 DeleteObject(editor
->hbrBackground
);
2342 lColor
= editor
->rgbBackColor
;
2344 else lColor
= GetSysColor(COLOR_WINDOW
);
2348 editor
->rgbBackColor
= -1;
2349 editor
->hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
2353 editor
->rgbBackColor
= lParam
;
2354 editor
->hbrBackground
= CreateSolidBrush(editor
->rgbBackColor
);
2356 if (editor
->bRedraw
)
2358 InvalidateRect(hWnd
, NULL
, TRUE
);
2364 return editor
->nModifyStep
== 0 ? 0 : -1;
2368 editor
->nModifyStep
= 1;
2370 editor
->nModifyStep
= 0;
2374 case EM_SETREADONLY
:
2376 long nStyle
= GetWindowLongW(hWnd
, GWL_STYLE
);
2378 nStyle
|= ES_READONLY
;
2380 nStyle
&= ~ES_READONLY
;
2381 SetWindowLongW(hWnd
, GWL_STYLE
, nStyle
);
2384 case EM_SETEVENTMASK
:
2386 DWORD nOldMask
= editor
->nEventMask
;
2388 editor
->nEventMask
= lParam
;
2391 case EM_GETEVENTMASK
:
2392 return editor
->nEventMask
;
2393 case EM_SETCHARFORMAT
:
2395 CHARFORMAT2W buf
, *p
;
2396 BOOL bRepaint
= TRUE
;
2397 p
= ME_ToCF2W(&buf
, (CHARFORMAT2W
*)lParam
);
2398 if (p
== NULL
) return 0;
2400 ME_SetDefaultCharFormat(editor
, p
);
2401 else if (wParam
== (SCF_WORD
| SCF_SELECTION
)) {
2402 FIXME("EM_SETCHARFORMAT: word selection not supported\n");
2404 } else if (wParam
== SCF_ALL
) {
2405 if (editor
->mode
& TM_PLAINTEXT
)
2406 ME_SetDefaultCharFormat(editor
, p
);
2408 ME_SetCharFormat(editor
, 0, ME_GetTextLength(editor
), p
);
2409 editor
->nModifyStep
= 1;
2411 } else if (editor
->mode
& TM_PLAINTEXT
) {
2415 ME_GetSelection(editor
, &from
, &to
);
2416 bRepaint
= (from
!= to
);
2417 ME_SetSelectionCharFormat(editor
, p
);
2418 if (from
!= to
) editor
->nModifyStep
= 1;
2420 ME_CommitUndo(editor
);
2422 ME_RewrapRepaint(editor
);
2425 case EM_GETCHARFORMAT
:
2427 CHARFORMAT2W tmp
, *dst
= (CHARFORMAT2W
*)lParam
;
2428 if (dst
->cbSize
!= sizeof(CHARFORMATA
) &&
2429 dst
->cbSize
!= sizeof(CHARFORMATW
) &&
2430 dst
->cbSize
!= sizeof(CHARFORMAT2A
) &&
2431 dst
->cbSize
!= sizeof(CHARFORMAT2W
))
2433 tmp
.cbSize
= sizeof(tmp
);
2435 ME_GetDefaultCharFormat(editor
, &tmp
);
2437 ME_GetSelectionCharFormat(editor
, &tmp
);
2438 ME_CopyToCFAny(dst
, &tmp
);
2441 case EM_SETPARAFORMAT
:
2442 ME_SetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
2443 ME_RewrapRepaint(editor
);
2444 ME_CommitUndo(editor
);
2446 case EM_GETPARAFORMAT
:
2447 ME_GetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
2449 case EM_GETFIRSTVISIBLELINE
:
2451 ME_DisplayItem
*p
= editor
->pBuffer
->pFirst
;
2452 int y
= ME_GetYScrollPos(editor
);
2457 p
= ME_FindItemFwd(p
, diStartRowOrParagraphOrEnd
);
2458 if (p
->type
== diTextEnd
)
2460 if (p
->type
== diParagraph
) {
2461 ypara
= p
->member
.para
.nYPos
;
2464 ystart
= ypara
+ p
->member
.row
.nYPos
;
2465 yend
= ystart
+ p
->member
.row
.nHeight
;
2473 case EM_HIDESELECTION
:
2475 editor
->bHideSelection
= (wParam
!= 0);
2476 ME_InvalidateSelection(editor
);
2481 ME_ScrollDown(editor
, lParam
* 8); /* FIXME follow the original */
2482 return TRUE
; /* Should return false if a single line richedit control */
2487 ME_GetSelection(editor
, &from
, &to
);
2488 ME_InternalDeleteText(editor
, from
, to
-from
);
2489 ME_CommitUndo(editor
);
2490 ME_UpdateRepaint(editor
);
2497 LPWSTR wszText
= lParam
? ME_ToUnicode(unicode
, (void *)lParam
) : NULL
;
2498 size_t len
= wszText
? lstrlenW(wszText
) : 0;
2499 TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText
));
2501 ME_GetSelection(editor
, &from
, &to
);
2502 style
= ME_GetSelectionInsertStyle(editor
);
2503 ME_InternalDeleteText(editor
, from
, to
-from
);
2504 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, style
);
2505 ME_ReleaseStyle(style
);
2506 /* drop temporary style if line end */
2508 * FIXME question: does abc\n mean: put abc,
2509 * clear temp style, put \n? (would require a change)
2511 if (len
>0 && wszText
[len
-1] == '\n')
2512 ME_ClearTempStyle(editor
);
2513 ME_EndToUnicode(unicode
, wszText
);
2514 ME_CommitUndo(editor
);
2515 if (editor
->AutoURLDetect_bEnable
) ME_UpdateSelectionLinkAttribute(editor
);
2517 ME_EmptyUndoStack(editor
);
2518 ME_UpdateRepaint(editor
);
2521 case EM_SCROLLCARET
:
2523 int top
, bottom
; /* row's edges relative to document top */
2525 ME_DisplayItem
*para
, *row
;
2527 nPos
= ME_GetYScrollPos(editor
);
2528 row
= ME_RowStart(editor
->pCursors
[0].pRun
);
2529 para
= ME_GetParagraph(row
);
2530 top
= para
->member
.para
.nYPos
+ row
->member
.row
.nYPos
;
2531 bottom
= top
+ row
->member
.row
.nHeight
;
2533 if (top
< nPos
) /* caret above window */
2534 ME_ScrollAbs(editor
, top
);
2535 else if (nPos
+ editor
->sizeWindow
.cy
< bottom
) /*below*/
2536 ME_ScrollAbs(editor
, bottom
- editor
->sizeWindow
.cy
);
2544 BOOL bRepaint
= LOWORD(lParam
);
2547 wParam
= (WPARAM
)GetStockObject(SYSTEM_FONT
);
2548 GetObjectW((HGDIOBJ
)wParam
, sizeof(LOGFONTW
), &lf
);
2550 ME_CharFormatFromLogFont(hDC
, &lf
, &fmt
);
2551 ReleaseDC(hWnd
, hDC
);
2552 ME_SetCharFormat(editor
, 0, ME_GetTextLength(editor
), &fmt
);
2553 ME_SetDefaultCharFormat(editor
, &fmt
);
2555 ME_CommitUndo(editor
);
2557 ME_RewrapRepaint(editor
);
2562 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
));
2565 TRACE("WM_SETTEXT lParam==%lx\n",lParam
);
2566 if (!unicode
&& !strncmp((char *)lParam
, "{\\rtf", 5))
2568 /* Undocumented: WM_SETTEXT supports RTF text */
2569 ME_StreamInRTFString(editor
, 0, (char *)lParam
);
2573 LPWSTR wszText
= ME_ToUnicode(unicode
, (void *)lParam
);
2574 TRACE("WM_SETTEXT - %s\n", debugstr_w(wszText
)); /* debugstr_w() */
2575 if (lstrlenW(wszText
) > 0)
2579 /* uses default style! */
2580 if (!(GetWindowLongW(hWnd
, GWL_STYLE
) & ES_MULTILINE
))
2585 while (*p
!= '\0' && *p
!= '\r' && *p
!= '\n') p
++;
2588 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, editor
->pBuffer
->pDefaultStyle
);
2590 ME_EndToUnicode(unicode
, wszText
);
2594 TRACE("WM_SETTEXT - NULL\n");
2595 if (editor
->AutoURLDetect_bEnable
)
2597 ME_UpdateLinkAttribute(editor
, 0, -1);
2599 ME_SetSelection(editor
, 0, 0);
2600 editor
->nModifyStep
= 0;
2601 ME_CommitUndo(editor
);
2602 ME_EmptyUndoStack(editor
);
2603 ME_UpdateRepaint(editor
);
2608 UINT nRTFFormat
= RegisterClipboardFormatA("Rich Text Format");
2609 if (IsClipboardFormatAvailable(nRTFFormat
))
2611 if (IsClipboardFormatAvailable(CF_UNICODETEXT
))
2619 ME_GlobalDestStruct gds
;
2620 UINT nRTFFormat
= RegisterClipboardFormatA("Rich Text Format");
2623 if (IsClipboardFormatAvailable(nRTFFormat
))
2624 cf
= nRTFFormat
, dwFormat
= SF_RTF
;
2625 else if (IsClipboardFormatAvailable(CF_UNICODETEXT
))
2626 cf
= CF_UNICODETEXT
, dwFormat
= SF_TEXT
|SF_UNICODE
;
2630 if (!OpenClipboard(hWnd
))
2632 gds
.hData
= GetClipboardData(cf
);
2634 es
.dwCookie
= (DWORD
)&gds
;
2635 es
.pfnCallback
= dwFormat
== SF_RTF
? ME_ReadFromHGLOBALRTF
: ME_ReadFromHGLOBALUnicode
;
2636 ME_StreamIn(editor
, dwFormat
|SFF_SELECTION
, &es
, FALSE
);
2644 LPDATAOBJECT dataObj
= NULL
;
2648 if (editor
->cPasswordMask
)
2649 return 0; /* Copying or Cutting masked text isn't allowed */
2651 ME_GetSelection(editor
, &range
.cpMin
, &range
.cpMax
);
2652 if(editor
->lpOleCallback
)
2653 hr
= IRichEditOleCallback_GetClipboardData(editor
->lpOleCallback
, &range
, RECO_COPY
, &dataObj
);
2654 if(FAILED(hr
) || !dataObj
)
2655 hr
= ME_GetDataObject(editor
, &range
, &dataObj
);
2657 hr
= OleSetClipboard(dataObj
);
2658 IDataObject_Release(dataObj
);
2660 if (SUCCEEDED(hr
) && msg
== WM_CUT
)
2662 ME_InternalDeleteText(editor
, range
.cpMin
, range
.cpMax
-range
.cpMin
);
2663 ME_CommitUndo(editor
);
2664 ME_UpdateRepaint(editor
);
2668 case WM_GETTEXTLENGTH
:
2670 GETTEXTLENGTHEX how
;
2672 /* CR/LF conversion required in 2.0 mode, verbatim in 1.0 mode */
2673 how
.flags
= GTL_CLOSE
| (editor
->bEmulateVersion10
? 0 : GTL_USECRLF
) | GTL_NUMCHARS
;
2674 how
.codepage
= unicode
? 1200 : CP_ACP
;
2675 return ME_GetTextLengthEx(editor
, &how
);
2677 case EM_GETTEXTLENGTHEX
:
2678 return ME_GetTextLengthEx(editor
, (GETTEXTLENGTHEX
*)wParam
);
2683 LPSTR bufferA
= NULL
;
2684 LPWSTR bufferW
= NULL
;
2687 bufferW
= heap_alloc((wParam
+ 2) * sizeof(WCHAR
));
2689 bufferA
= heap_alloc(wParam
+ 2);
2691 ex
.cb
= (wParam
+ 2) * (unicode
? sizeof(WCHAR
) : sizeof(CHAR
));
2692 ex
.flags
= GT_USECRLF
;
2693 ex
.codepage
= unicode
? 1200 : CP_ACP
;
2694 ex
.lpDefaultChar
= NULL
;
2695 ex
.lpUsedDefChar
= NULL
;
2696 rc
= RichEditWndProc_common(hWnd
, EM_GETTEXTEX
, (WPARAM
)&ex
, unicode
? (LPARAM
)bufferW
: (LPARAM
)bufferA
, unicode
);
2700 memcpy((LPWSTR
)lParam
, bufferW
, wParam
* sizeof(WCHAR
));
2701 if (lstrlenW(bufferW
) >= wParam
) rc
= 0;
2705 memcpy((LPSTR
)lParam
, bufferA
, wParam
);
2706 if (strlen(bufferA
) >= wParam
) rc
= 0;
2714 GETTEXTEX
*ex
= (GETTEXTEX
*)wParam
;
2715 int nStart
, nCount
; /* in chars */
2717 if (ex
->flags
& ~(GT_SELECTION
| GT_USECRLF
))
2718 FIXME("GETTEXTEX flags 0x%08x not supported\n", ex
->flags
& ~(GT_SELECTION
| GT_USECRLF
));
2720 if (ex
->flags
& GT_SELECTION
)
2722 ME_GetSelection(editor
, &nStart
, &nCount
);
2728 nCount
= 0x7fffffff;
2730 if (ex
->codepage
== 1200)
2732 nCount
= min(nCount
, ex
->cb
/ sizeof(WCHAR
) - 1);
2733 return ME_GetTextW(editor
, (LPWSTR
)lParam
, nStart
, nCount
, ex
->flags
& GT_USECRLF
);
2737 /* potentially each char may be a CR, why calculate the exact value with O(N) when
2738 we can just take a bigger buffer? :)
2739 The above assumption still holds with CR/LF counters, since CR->CRLF expansion
2740 occurs only in richedit 2.0 mode, in which line breaks have only one CR
2742 int crlfmul
= (ex
->flags
& GT_USECRLF
) ? 2 : 1;
2744 DWORD buflen
= ex
->cb
;
2748 nCount
= min(nCount
, ex
->cb
- 1);
2749 buffer
= heap_alloc((crlfmul
*nCount
+ 1) * sizeof(WCHAR
));
2751 buflen
= ME_GetTextW(editor
, buffer
, nStart
, nCount
, ex
->flags
& GT_USECRLF
);
2752 rc
= WideCharToMultiByte(ex
->codepage
, flags
, buffer
, buflen
+1, (LPSTR
)lParam
, ex
->cb
, ex
->lpDefaultChar
, ex
->lpUsedDefChar
);
2753 if (rc
) rc
--; /* do not count 0 terminator */
2762 TEXTRANGEW tr
; /* W and A differ only by rng->lpstrText */
2763 ME_GetSelection(editor
, &from
, &to
);
2764 tr
.chrg
.cpMin
= from
;
2766 tr
.lpstrText
= (WCHAR
*)lParam
;
2767 return RichEditWndProc_common(hWnd
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
, unicode
);
2769 case EM_GETSCROLLPOS
:
2771 POINT
*point
= (POINT
*)lParam
;
2772 point
->x
= 0; /* FIXME side scrolling not implemented */
2773 point
->y
= ME_GetYScrollPos(editor
);
2776 case EM_GETTEXTRANGE
:
2778 TEXTRANGEW
*rng
= (TEXTRANGEW
*)lParam
;
2779 TRACE("EM_GETTEXTRANGE min=%d max=%d unicode=%d emul1.0=%d length=%d\n",
2780 rng
->chrg
.cpMin
, rng
->chrg
.cpMax
, unicode
,
2781 editor
->bEmulateVersion10
, ME_GetTextLength(editor
));
2783 return ME_GetTextW(editor
, rng
->lpstrText
, rng
->chrg
.cpMin
, rng
->chrg
.cpMax
-rng
->chrg
.cpMin
, 0);
2786 int nLen
= rng
->chrg
.cpMax
-rng
->chrg
.cpMin
;
2787 WCHAR
*p
= ALLOC_N_OBJ(WCHAR
, nLen
+1);
2788 int nChars
= ME_GetTextW(editor
, p
, rng
->chrg
.cpMin
, nLen
, 0);
2789 /* FIXME this is a potential security hole (buffer overrun)
2790 if you know more about wchar->mbyte conversion please explain
2792 WideCharToMultiByte(CP_ACP
, 0, p
, nChars
+1, (char *)rng
->lpstrText
, nLen
+1, NULL
, NULL
);
2799 ME_DisplayItem
*run
;
2800 const unsigned int nMaxChars
= *(WORD
*) lParam
;
2801 unsigned int nCharsLeft
= nMaxChars
;
2802 char *dest
= (char *) lParam
;
2803 BOOL wroteNull
= FALSE
;
2805 TRACE("EM_GETLINE: row=%d, nMaxChars=%d (%s)\n", (int) wParam
, nMaxChars
,
2806 unicode
? "Unicode" : "Ansi");
2808 run
= ME_FindRowWithNumber(editor
, wParam
);
2812 while (nCharsLeft
&& (run
= ME_FindItemFwd(run
, diRunOrStartRow
))
2813 && !(run
->member
.run
.nFlags
& MERF_ENDPARA
))
2817 if (run
->type
!= diRun
)
2819 strText
= run
->member
.run
.strText
;
2820 nCopy
= min(nCharsLeft
, strText
->nLen
);
2823 lstrcpynW((LPWSTR
) dest
, strText
->szData
, nCopy
);
2825 nCopy
= WideCharToMultiByte(CP_ACP
, 0, strText
->szData
, nCopy
, dest
,
2826 nCharsLeft
, NULL
, NULL
);
2827 dest
+= nCopy
* (unicode
? sizeof(WCHAR
) : 1);
2828 nCharsLeft
-= nCopy
;
2831 /* append line termination, space allowing */
2834 if (run
&& (run
->member
.run
.nFlags
& MERF_ENDPARA
))
2837 /* Write as many \r as encoded in end-of-paragraph, space allowing */
2838 for (i
= 0; i
< run
->member
.run
.nCR
&& nCharsLeft
> 0; i
++, nCharsLeft
--)
2840 *((WCHAR
*)dest
) = '\r';
2841 dest
+= unicode
? sizeof(WCHAR
) : 1;
2843 /* Write as many \n as encoded in end-of-paragraph, space allowing */
2844 for (i
= 0; i
< run
->member
.run
.nLF
&& nCharsLeft
> 0; i
++, nCharsLeft
--)
2846 *((WCHAR
*)dest
) = '\n';
2847 dest
+= unicode
? sizeof(WCHAR
) : 1;
2853 *((WCHAR
*)dest
) = '\0';
2861 TRACE("EM_GETLINE: got %u characters\n", nMaxChars
- nCharsLeft
);
2862 return nMaxChars
- nCharsLeft
- (wroteNull
? 1 : 0);
2864 case EM_GETLINECOUNT
:
2866 ME_DisplayItem
*item
= editor
->pBuffer
->pFirst
->next
;
2869 ME_DisplayItem
*prev_para
= NULL
, *last_para
= NULL
;
2871 while (item
!= editor
->pBuffer
->pLast
)
2873 assert(item
->type
== diParagraph
);
2874 prev_para
= ME_FindItemBack(item
, diRun
);
2876 assert(prev_para
->member
.run
.nFlags
& MERF_ENDPARA
);
2878 nRows
+= item
->member
.para
.nRows
;
2879 item
= item
->member
.para
.next_para
;
2881 last_para
= ME_FindItemBack(item
, diRun
);
2883 assert(last_para
->member
.run
.nFlags
& MERF_ENDPARA
);
2884 if (editor
->bEmulateVersion10
&& prev_para
&& last_para
->member
.run
.nCharOfs
== 0
2885 && prev_para
->member
.run
.nCR
== 1 && prev_para
->member
.run
.nLF
== 0)
2887 /* In 1.0 emulation, the last solitary \r at the very end of the text
2888 (if one exists) is NOT a line break.
2889 FIXME: this is an ugly hack. This should have a more regular model. */
2893 TRACE("EM_GETLINECOUNT: nRows==%d\n", nRows
);
2894 return max(1, nRows
);
2896 case EM_LINEFROMCHAR
:
2899 return ME_RowNumberFromCharOfs(editor
, ME_GetCursorOfs(editor
, 1));
2901 return ME_RowNumberFromCharOfs(editor
, wParam
);
2903 case EM_EXLINEFROMCHAR
:
2906 return ME_RowNumberFromCharOfs(editor
, ME_GetCursorOfs(editor
,1));
2908 return ME_RowNumberFromCharOfs(editor
, lParam
);
2912 ME_DisplayItem
*item
, *para
;
2916 item
= ME_FindItemBack(editor
->pCursors
[0].pRun
, diStartRow
);
2918 item
= ME_FindRowWithNumber(editor
, wParam
);
2921 para
= ME_GetParagraph(item
);
2922 item
= ME_FindItemFwd(item
, diRun
);
2923 nCharOfs
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
;
2924 TRACE("EM_LINEINDEX: nCharOfs==%d\n", nCharOfs
);
2929 ME_DisplayItem
*item
, *item_end
;
2930 int nChars
= 0, nThisLineOfs
= 0, nNextLineOfs
= 0;
2932 if (wParam
> ME_GetTextLength(editor
))
2936 FIXME("EM_LINELENGTH: returning number of unselected characters on lines with selection unsupported.\n");
2939 item
= ME_FindItemAtOffset(editor
, diRun
, wParam
, NULL
);
2940 item
= ME_RowStart(item
);
2941 nThisLineOfs
= ME_CharOfsFromRunOfs(editor
, ME_FindItemFwd(item
, diRun
), 0);
2942 item_end
= ME_FindItemFwd(item
, diStartRowOrParagraphOrEnd
);
2943 if (item_end
->type
== diStartRow
)
2944 nNextLineOfs
= ME_CharOfsFromRunOfs(editor
, ME_FindItemFwd(item_end
, diRun
), 0);
2947 ME_DisplayItem
*endPara
;
2949 nNextLineOfs
= ME_FindItemFwd(item
, diParagraphOrEnd
)->member
.para
.nCharOfs
;
2950 endPara
= ME_FindItemFwd(item
, diParagraphOrEnd
);
2951 endPara
= ME_FindItemBack(endPara
, diRun
);
2953 assert(endPara
->type
== diRun
);
2954 assert(endPara
->member
.run
.nFlags
& MERF_ENDPARA
);
2955 nNextLineOfs
-= endPara
->member
.run
.nCR
+ endPara
->member
.run
.nLF
;
2957 nChars
= nNextLineOfs
- nThisLineOfs
;
2958 TRACE("EM_LINELENGTH(%ld)==%d\n",wParam
, nChars
);
2961 case EM_EXLIMITTEXT
:
2963 if ((int)lParam
< 0)
2966 editor
->nTextLimit
= 65536;
2968 editor
->nTextLimit
= (int) lParam
;
2974 editor
->nTextLimit
= 65536;
2976 editor
->nTextLimit
= (int) wParam
;
2979 case EM_GETLIMITTEXT
:
2981 return editor
->nTextLimit
;
2985 FINDTEXTA
*ft
= (FINDTEXTA
*)lParam
;
2986 int nChars
= MultiByteToWideChar(CP_ACP
, 0, ft
->lpstrText
, -1, NULL
, 0);
2990 if ((tmp
= ALLOC_N_OBJ(WCHAR
, nChars
)) != NULL
)
2991 MultiByteToWideChar(CP_ACP
, 0, ft
->lpstrText
, -1, tmp
, nChars
);
2992 r
= ME_FindText(editor
, wParam
, &ft
->chrg
, tmp
, NULL
);
2998 FINDTEXTEXA
*ex
= (FINDTEXTEXA
*)lParam
;
2999 int nChars
= MultiByteToWideChar(CP_ACP
, 0, ex
->lpstrText
, -1, NULL
, 0);
3003 if ((tmp
= ALLOC_N_OBJ(WCHAR
, nChars
)) != NULL
)
3004 MultiByteToWideChar(CP_ACP
, 0, ex
->lpstrText
, -1, tmp
, nChars
);
3005 r
= ME_FindText(editor
, wParam
, &ex
->chrg
, tmp
, &ex
->chrgText
);
3011 FINDTEXTW
*ft
= (FINDTEXTW
*)lParam
;
3012 return ME_FindText(editor
, wParam
, &ft
->chrg
, ft
->lpstrText
, NULL
);
3014 case EM_FINDTEXTEXW
:
3016 FINDTEXTEXW
*ex
= (FINDTEXTEXW
*)lParam
;
3017 return ME_FindText(editor
, wParam
, &ex
->chrg
, ex
->lpstrText
, &ex
->chrgText
);
3020 if (!wParam
|| !lParam
)
3022 *(int *)wParam
= editor
->nZoomNumerator
;
3023 *(int *)lParam
= editor
->nZoomDenominator
;
3026 return ME_SetZoom(editor
, wParam
, lParam
);
3027 case EM_CHARFROMPOS
:
3028 return ME_CharFromPos(editor
, ((POINTL
*)lParam
)->x
, ((POINTL
*)lParam
)->y
, NULL
);
3029 case EM_POSFROMCHAR
:
3031 ME_DisplayItem
*pRun
;
3032 int nCharOfs
, nOffset
, nLength
;
3037 /* detect which API version we're dealing with */
3038 if (wParam
>= 0x40000)
3040 nLength
= ME_GetTextLength(editor
);
3042 if (nCharOfs
< nLength
) {
3043 ME_RunOfsFromCharOfs(editor
, nCharOfs
, &pRun
, &nOffset
);
3044 assert(pRun
->type
== diRun
);
3045 pt
.y
= pRun
->member
.run
.pt
.y
;
3046 pt
.x
= pRun
->member
.run
.pt
.x
+ ME_PointFromChar(editor
, &pRun
->member
.run
, nOffset
);
3047 pt
.y
+= ME_GetParagraph(pRun
)->member
.para
.nYPos
;
3050 pt
.y
= editor
->pBuffer
->pLast
->member
.para
.nYPos
;
3052 pt
.x
+= editor
->selofs
;
3054 si
.cbSize
= sizeof(si
);
3056 if (GetScrollInfo(editor
->hWnd
, SB_VERT
, &si
)) pt
.y
-= si
.nPos
;
3057 si
.cbSize
= sizeof(si
);
3059 if (GetScrollInfo(editor
->hWnd
, SB_HORZ
, &si
)) pt
.x
-= si
.nPos
;
3061 if (wParam
>= 0x40000) {
3062 *(POINTL
*)wParam
= pt
;
3064 return (wParam
>= 0x40000) ? 0 : MAKELONG( pt
.x
, pt
.y
);
3070 GetClientRect(hWnd
, &editor
->rcFormat
);
3071 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_HSCROLL
)
3072 { /* Squelch the default horizontal scrollbar it would make */
3073 ShowScrollBar(editor
->hWnd
, SB_HORZ
, FALSE
);
3076 si
.cbSize
= sizeof(si
);
3077 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
3078 if (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_DISABLENOSCROLL
)
3079 si
.fMask
|= SIF_DISABLENOSCROLL
;
3080 si
.nMax
= (si
.fMask
& SIF_DISABLENOSCROLL
) ? 1 : 0;
3083 SetScrollInfo(hWnd
, SB_VERT
, &si
, TRUE
);
3085 ME_CommitUndo(editor
);
3086 ME_WrapMarkedParagraphs(editor
);
3087 ME_MoveCaret(editor
);
3091 ME_DestroyEditor(editor
);
3092 SetWindowLongPtrW(hWnd
, 0, 0);
3096 return ME_SetCursor(editor
);
3098 case WM_LBUTTONDBLCLK
:
3099 case WM_LBUTTONDOWN
:
3101 ME_CommitUndo(editor
); /* End coalesced undos for typed characters */
3102 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
3103 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3106 ME_LButtonDown(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
),
3107 ME_CalculateClickCount(hWnd
, msg
, wParam
, lParam
));
3109 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
3110 if (!ME_SetCursor(editor
)) goto do_default
;
3114 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
3115 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3117 if (GetCapture() == hWnd
)
3118 ME_MouseMove(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
3119 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
3120 /* Set cursor if mouse is captured, since WM_SETCURSOR won't be received. */
3121 if (GetCapture() == hWnd
)
3122 ME_SetCursor(editor
);
3125 if (GetCapture() == hWnd
)
3127 if (editor
->nSelectionType
== stDocument
)
3128 editor
->nSelectionType
= stPosition
;
3129 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
3130 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3134 ME_SetCursor(editor
);
3135 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
3139 case WM_RBUTTONDOWN
:
3140 ME_CommitUndo(editor
); /* End coalesced undos for typed characters */
3141 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
3142 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3145 case WM_CONTEXTMENU
:
3146 if (!ME_ShowContextMenu(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
)))
3150 if (editor
->bRedraw
)
3155 hDC
= BeginPaint(hWnd
, &ps
);
3156 ME_PaintContent(editor
, hDC
, FALSE
, &ps
.rcPaint
);
3157 EndPaint(hWnd
, &ps
);
3161 editor
->bHaveFocus
= TRUE
;
3162 ME_ShowCaret(editor
);
3163 ME_SendOldNotify(editor
, EN_SETFOCUS
);
3166 ME_CommitUndo(editor
); /* End coalesced undos for typed characters */
3167 editor
->bHaveFocus
= FALSE
;
3168 ME_HideCaret(editor
);
3169 ME_SendOldNotify(editor
, EN_KILLFOCUS
);
3173 if (editor
->bRedraw
)
3175 HDC hDC
= (HDC
)wParam
;
3177 if (GetUpdateRect(hWnd
,&rc
,TRUE
))
3179 FillRect(hDC
, &rc
, editor
->hbrBackground
);
3185 TRACE("editor wnd command = %d\n", LOWORD(wParam
));
3188 if ((editor
->nEventMask
& ENM_KEYEVENTS
) &&
3189 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3193 if ((editor
->nEventMask
& ENM_KEYEVENTS
) &&
3194 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3196 if (ME_KeyDown(editor
, LOWORD(wParam
)))
3204 wstr
= (WCHAR
)wParam
;
3207 CHAR charA
= wParam
;
3208 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &wstr
, 1);
3213 case 1: /* Ctrl-A */
3214 ME_SetSelection(editor
, 0, -1);
3216 case 3: /* Ctrl-C */
3217 SendMessageW(editor
->hWnd
, WM_COPY
, 0, 0);
3221 if (GetWindowLongW(editor
->hWnd
, GWL_STYLE
) & ES_READONLY
) {
3222 MessageBeep(MB_ICONERROR
);
3223 return 0; /* FIXME really 0 ? */
3228 case 22: /* Ctrl-V */
3229 SendMessageW(editor
->hWnd
, WM_PASTE
, 0, 0);
3231 case 24: /* Ctrl-X */
3232 SendMessageW(editor
->hWnd
, WM_CUT
, 0, 0);
3234 case 25: /* Ctrl-Y */
3235 SendMessageW(editor
->hWnd
, EM_REDO
, 0, 0);
3237 case 26: /* Ctrl-Z */
3238 SendMessageW(editor
->hWnd
, EM_UNDO
, 0, 0);
3241 if (((unsigned)wstr
)>=' '
3242 || (wstr
=='\r' && (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_MULTILINE
))
3244 /* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */
3245 /* WM_CHAR is restricted to nTextLimit */
3247 ME_GetSelection(editor
, &from
, &to
);
3248 if(editor
->nTextLimit
> ME_GetTextLength(editor
) - (to
-from
))
3250 ME_Style
*style
= ME_GetInsertStyle(editor
, 0);
3251 ME_SaveTempStyle(editor
);
3252 ME_ContinueCoalescingTransaction(editor
);
3253 if (wstr
== '\r' && (GetKeyState(VK_SHIFT
) & 0x8000))
3254 ME_InsertEndRowFromCursor(editor
, 0);
3256 ME_InsertTextFromCursor(editor
, 0, &wstr
, 1, style
);
3257 ME_ReleaseStyle(style
);
3258 ME_CommitCoalescingUndo(editor
);
3262 if (editor
->AutoURLDetect_bEnable
) ME_UpdateSelectionLinkAttribute(editor
);
3264 ME_UpdateRepaint(editor
);
3271 if(wParam
== UNICODE_NOCHAR
) return TRUE
;
3272 if(wParam
<= 0x000fffff)
3274 if(wParam
> 0xffff) /* convert to surrogates */
3277 SendMessageW(editor
->hWnd
, WM_CHAR
, (wParam
>> 10) + 0xd800, 0);
3278 SendMessageW(editor
->hWnd
, WM_CHAR
, (wParam
& 0x03ff) + 0xdc00, 0);
3280 else SendMessageW(editor
->hWnd
, WM_CHAR
, wParam
, 0);
3285 case EM_STOPGROUPTYPING
:
3286 ME_CommitUndo(editor
); /* End coalesced undos for typed characters */
3288 case EM_SCROLL
: /* fall through */
3294 origNPos
= ME_GetYScrollPos(editor
);
3297 if (editor
&& editor
->pBuffer
&& editor
->pBuffer
->pDefaultStyle
)
3298 lineHeight
= editor
->pBuffer
->pDefaultStyle
->tm
.tmHeight
;
3299 if (lineHeight
<= 0) lineHeight
= 24;
3301 switch(LOWORD(wParam
))
3304 ME_ScrollUp(editor
,lineHeight
);
3307 ME_ScrollDown(editor
,lineHeight
);
3310 ME_ScrollUp(editor
,editor
->sizeWindow
.cy
);
3313 ME_ScrollDown(editor
,editor
->sizeWindow
.cy
);
3316 case SB_THUMBPOSITION
:
3317 ME_ScrollAbs(editor
,HIWORD(wParam
));
3320 if (msg
== EM_SCROLL
)
3321 return 0x00010000 | (((ME_GetYScrollPos(editor
) - origNPos
)/lineHeight
) & 0xffff);
3327 UINT pulScrollLines
;
3329 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
3330 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3333 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
3334 gcWheelDelta
= -GET_WHEEL_DELTA_WPARAM(wParam
);
3336 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
3338 /* FIXME follow the original */
3339 ME_ScrollDown(editor
,pulScrollLines
* (gcWheelDelta
/ WHEEL_DELTA
) * 8);
3345 *((RECT
*)lParam
) = editor
->rcFormat
;
3353 RECT
*rc
= (RECT
*)lParam
;
3357 editor
->rcFormat
.left
+= rc
->left
;
3358 editor
->rcFormat
.top
+= rc
->top
;
3359 editor
->rcFormat
.right
+= rc
->right
;
3360 editor
->rcFormat
.bottom
+= rc
->bottom
;
3364 editor
->rcFormat
= *rc
;
3369 GetClientRect(hWnd
, &editor
->rcFormat
);
3371 if (msg
!= EM_SETRECTNP
)
3372 ME_RewrapRepaint(editor
);
3375 case EM_REQUESTRESIZE
:
3376 ME_SendRequestResize(editor
, TRUE
);
3379 if ((editor
->bRedraw
= wParam
))
3380 ME_RewrapRepaint(editor
);
3384 GetClientRect(hWnd
, &editor
->rcFormat
);
3385 ME_RewrapRepaint(editor
);
3386 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
3388 /* IME messages to make richedit controls IME aware */
3389 case WM_IME_SETCONTEXT
:
3390 case WM_IME_CONTROL
:
3392 case WM_IME_COMPOSITIONFULL
:
3394 case WM_IME_STARTCOMPOSITION
:
3396 editor
->imeStartIndex
=ME_GetCursorOfs(editor
,0);
3397 ME_DeleteSelection(editor
);
3398 ME_CommitUndo(editor
);
3399 ME_UpdateRepaint(editor
);
3402 case WM_IME_COMPOSITION
:
3406 ME_Style
*style
= ME_GetInsertStyle(editor
, 0);
3407 hIMC
= ImmGetContext(hWnd
);
3408 ME_DeleteSelection(editor
);
3409 ME_CommitUndo(editor
);
3410 ME_SaveTempStyle(editor
);
3411 if (lParam
& GCS_RESULTSTR
)
3413 LPWSTR lpCompStr
= NULL
;
3416 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
3417 lpCompStr
= HeapAlloc(GetProcessHeap(),0,dwBufLen
+ sizeof(WCHAR
));
3418 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpCompStr
, dwBufLen
);
3419 lpCompStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
3420 ME_InsertTextFromCursor(editor
,0,lpCompStr
,dwBufLen
/sizeof(WCHAR
),style
);
3422 else if (lParam
& GCS_COMPSTR
)
3424 LPWSTR lpCompStr
= NULL
;
3427 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
3428 lpCompStr
= HeapAlloc(GetProcessHeap(),0,dwBufLen
+ sizeof(WCHAR
));
3429 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, dwBufLen
);
3430 lpCompStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
3432 ME_InsertTextFromCursor(editor
,0,lpCompStr
,dwBufLen
/sizeof(WCHAR
),style
);
3433 ME_SetSelection(editor
,editor
->imeStartIndex
,
3434 editor
->imeStartIndex
+ dwBufLen
/sizeof(WCHAR
));
3436 ME_ReleaseStyle(style
);
3437 ME_UpdateRepaint(editor
);
3440 case WM_IME_ENDCOMPOSITION
:
3442 ME_DeleteSelection(editor
);
3443 editor
->imeStartIndex
=-1;
3446 case EM_GETOLEINTERFACE
:
3448 LPVOID
*ppvObj
= (LPVOID
*) lParam
;
3449 return CreateIRichEditOle(editor
, ppvObj
);
3451 case EM_GETPASSWORDCHAR
:
3453 return editor
->cPasswordMask
;
3455 case EM_SETOLECALLBACK
:
3456 if(editor
->lpOleCallback
)
3457 IUnknown_Release(editor
->lpOleCallback
);
3458 editor
->lpOleCallback
= (LPRICHEDITOLECALLBACK
)lParam
;
3459 if(editor
->lpOleCallback
)
3460 IUnknown_AddRef(editor
->lpOleCallback
);
3462 case EM_GETWORDBREAKPROC
:
3463 return (LRESULT
)editor
->pfnWordBreak
;
3464 case EM_SETWORDBREAKPROC
:
3466 EDITWORDBREAKPROCW pfnOld
= editor
->pfnWordBreak
;
3468 editor
->pfnWordBreak
= (EDITWORDBREAKPROCW
)lParam
;
3469 return (LRESULT
)pfnOld
;
3471 case EM_SETTEXTMODE
:
3476 ret
= RichEditWndProc_common(hWnd
, WM_GETTEXTLENGTH
, 0, 0, unicode
);
3479 /*Check for valid wParam*/
3480 if ((((wParam
& TM_RICHTEXT
) && ((wParam
& TM_PLAINTEXT
) << 1))) ||
3481 (((wParam
& TM_MULTILEVELUNDO
) && ((wParam
& TM_SINGLELEVELUNDO
) << 1))) ||
3482 (((wParam
& TM_MULTICODEPAGE
) && ((wParam
& TM_SINGLECODEPAGE
) << 1))))
3486 if (wParam
& (TM_RICHTEXT
| TM_PLAINTEXT
))
3488 mask
|= (TM_RICHTEXT
| TM_PLAINTEXT
);
3489 changes
|= (wParam
& (TM_RICHTEXT
| TM_PLAINTEXT
));
3491 /*FIXME: Currently no support for undo level and code page options*/
3492 editor
->mode
= (editor
->mode
& (~mask
)) | changes
;
3498 case EM_SETPASSWORDCHAR
:
3500 editor
->cPasswordMask
= wParam
;
3501 ME_RewrapRepaint(editor
);
3504 case EM_SETTARGETDEVICE
:
3507 BOOL
new = (lParam
== 0);
3508 if (editor
->bWordWrap
!= new)
3510 editor
->bWordWrap
= new;
3511 ME_RewrapRepaint(editor
);
3514 else FIXME("Unsupported yet non NULL device in EM_SETTARGETDEVICE\n");
3518 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
3523 static LRESULT WINAPI
RichEditWndProcW(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
3525 BOOL unicode
= TRUE
;
3527 /* Under Win9x RichEdit20W returns ANSI strings, see the tests. */
3528 if (msg
== WM_GETTEXT
&& (GetVersion() & 0x80000000))
3531 return RichEditWndProc_common(hWnd
, msg
, wParam
, lParam
, unicode
);
3534 static LRESULT WINAPI
RichEditWndProcA(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
3536 return RichEditWndProc_common(hWnd
, msg
, wParam
, lParam
, FALSE
);
3539 /******************************************************************
3540 * RichEditANSIWndProc (RICHED20.10)
3542 LRESULT WINAPI
RichEditANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
3544 return RichEditWndProcA(hWnd
, msg
, wParam
, lParam
);
3547 /******************************************************************
3548 * RichEdit10ANSIWndProc (RICHED20.9)
3550 LRESULT WINAPI
RichEdit10ANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
3554 /* FIXME: this is NOT the same as 2.0 version */
3555 result
= RichEditANSIWndProc(hWnd
, msg
, wParam
, lParam
);
3556 if (msg
== WM_NCCREATE
)
3558 ME_TextEditor
*editor
= (ME_TextEditor
*)GetWindowLongPtrW(hWnd
, 0);
3560 editor
->bEmulateVersion10
= TRUE
;
3561 editor
->pBuffer
->pLast
->member
.para
.nCharOfs
= 2;
3562 assert(editor
->pBuffer
->pLast
->prev
->type
== diRun
);
3563 assert(editor
->pBuffer
->pLast
->prev
->member
.run
.nFlags
& MERF_ENDPARA
);
3564 editor
->pBuffer
->pLast
->prev
->member
.run
.nLF
= 1;
3569 void ME_SendOldNotify(ME_TextEditor
*editor
, int nCode
)
3571 HWND hWnd
= editor
->hWnd
;
3572 SendMessageA(GetParent(hWnd
), WM_COMMAND
, (nCode
<<16)|GetWindowLongW(hWnd
, GWLP_ID
), (LPARAM
)hWnd
);
3575 void ME_LinkNotify(ME_TextEditor
*editor
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
3578 ME_Cursor tmpCursor
;
3580 int nCharOfs
; /* The start of the clicked text. Absolute character offset */
3585 x
= (short)LOWORD(lParam
);
3586 y
= (short)HIWORD(lParam
);
3587 nCharOfs
= ME_CharFromPos(editor
, x
, y
, &isExact
);
3588 if (!isExact
) return;
3590 ME_CursorFromCharOfs(editor
, nCharOfs
, &tmpCursor
);
3591 tmpRun
= &tmpCursor
.pRun
->member
.run
;
3593 if ((tmpRun
->style
->fmt
.dwMask
& CFM_LINK
)
3594 && (tmpRun
->style
->fmt
.dwEffects
& CFE_LINK
))
3595 { /* The clicked run has CFE_LINK set */
3596 info
.nmhdr
.hwndFrom
= editor
->hWnd
;
3597 info
.nmhdr
.idFrom
= GetWindowLongW(editor
->hWnd
, GWLP_ID
);
3598 info
.nmhdr
.code
= EN_LINK
;
3600 info
.wParam
= wParam
;
3601 info
.lParam
= lParam
;
3602 info
.chrg
.cpMin
= ME_CharOfsFromRunOfs(editor
,tmpCursor
.pRun
,0);
3603 info
.chrg
.cpMax
= info
.chrg
.cpMin
+ ME_StrVLen(tmpRun
->strText
);
3604 SendMessageW(GetParent(editor
->hWnd
), WM_NOTIFY
,info
.nmhdr
.idFrom
, (LPARAM
)&info
);
3608 int ME_CountParagraphsBetween(ME_TextEditor
*editor
, int from
, int to
)
3610 ME_DisplayItem
*item
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
3613 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= from
)
3614 item
= item
->member
.para
.next_para
;
3617 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= to
) {
3618 item
= item
->member
.para
.next_para
;
3625 int ME_GetTextW(ME_TextEditor
*editor
, WCHAR
*buffer
, int nStart
, int nChars
, int bCRLF
)
3627 ME_DisplayItem
*item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
3629 WCHAR
*pStart
= buffer
;
3636 /* bCRLF flag is only honored in 2.0 and up. 1.0 must always return text verbatim */
3637 if (editor
->bEmulateVersion10
) bCRLF
= 0;
3641 int nLen
= ME_StrLen(item
->member
.run
.strText
) - nStart
;
3644 CopyMemory(buffer
, item
->member
.run
.strText
->szData
+ nStart
, sizeof(WCHAR
)*nLen
);
3653 item
= ME_FindItemFwd(item
, diRun
);
3656 while(nChars
&& item
)
3658 int nLen
= ME_StrLen(item
->member
.run
.strText
);
3659 if (item
->member
.run
.nFlags
& MERF_ENDPARA
)
3660 nLen
= item
->member
.run
.nCR
+ item
->member
.run
.nLF
;
3664 if (item
->member
.run
.nFlags
& MERF_ENDPARA
)
3666 if (!ME_FindItemFwd(item
, diRun
))
3667 /* No '\r' is appended to the last paragraph. */
3669 else if (bCRLF
&& nChars
== 1) {
3675 /* richedit 2.0 case - actual line-break is \r but should report \r\n */
3678 *buffer
= '\n'; /* Later updated by nLen==1 at the end of the loop */
3685 /* richedit 2.0 verbatim has only \r. richedit 1.0 should honor encodings */
3687 while (nChars
- i
> 0 && i
< item
->member
.run
.nCR
)
3689 buffer
[i
] = '\r'; i
++;
3692 while (nChars
- i
- j
> 0 && j
< item
->member
.run
.nLF
)
3694 buffer
[i
+j
] = '\n'; j
++;
3700 CopyMemory(buffer
, item
->member
.run
.strText
->szData
, sizeof(WCHAR
)*nLen
);
3707 TRACE("nWritten=%d, actual=%d\n", nWritten
, buffer
-pStart
);
3711 item
= ME_FindItemFwd(item
, diRun
);
3714 TRACE("nWritten=%d, actual=%d\n", nWritten
, buffer
-pStart
);
3718 static BOOL
ME_RegisterEditorClass(HINSTANCE hInstance
)
3723 wcW
.style
= CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
;
3724 wcW
.lpfnWndProc
= RichEditWndProcW
;
3726 wcW
.cbWndExtra
= sizeof(ME_TextEditor
*);
3727 wcW
.hInstance
= NULL
; /* hInstance would register DLL-local class */
3729 wcW
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
3730 wcW
.hbrBackground
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
3731 wcW
.lpszMenuName
= NULL
;
3733 if (is_version_nt())
3735 wcW
.lpszClassName
= RichEdit20W
;
3736 if (!RegisterClassW(&wcW
)) return FALSE
;
3737 wcW
.lpszClassName
= RichEdit50W
;
3738 if (!RegisterClassW(&wcW
)) return FALSE
;
3742 /* WNDCLASSA/W have the same layout */
3743 wcW
.lpszClassName
= (LPCWSTR
)"RichEdit20W";
3744 if (!RegisterClassA((WNDCLASSA
*)&wcW
)) return FALSE
;
3745 wcW
.lpszClassName
= (LPCWSTR
)"RichEdit50W";
3746 if (!RegisterClassA((WNDCLASSA
*)&wcW
)) return FALSE
;
3749 wcA
.style
= CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
;
3750 wcA
.lpfnWndProc
= RichEditWndProcA
;
3752 wcA
.cbWndExtra
= sizeof(ME_TextEditor
*);
3753 wcA
.hInstance
= NULL
; /* hInstance would register DLL-local class */
3755 wcA
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
3756 wcA
.hbrBackground
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
3757 wcA
.lpszMenuName
= NULL
;
3758 wcA
.lpszClassName
= "RichEdit20A";
3759 if (!RegisterClassA(&wcA
)) return FALSE
;
3760 wcA
.lpszClassName
= "RichEdit50A";
3761 if (!RegisterClassA(&wcA
)) return FALSE
;
3766 LRESULT WINAPI
REComboWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
) {
3767 /* FIXME: Not implemented */
3768 TRACE("hWnd %p msg %04x (%s) %08lx %08lx\n",
3769 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
);
3770 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
3773 LRESULT WINAPI
REListWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
) {
3774 /* FIXME: Not implemented */
3775 TRACE("hWnd %p msg %04x (%s) %08lx %08lx\n",
3776 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
);
3777 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
3780 /******************************************************************
3781 * REExtendedRegisterClass (RICHED20.8)
3783 * FIXME undocumented
3784 * Need to check for errors and implement controls and callbacks
3786 LRESULT WINAPI
REExtendedRegisterClass(void)
3791 FIXME("semi stub\n");
3795 wcW
.hInstance
= NULL
;
3798 wcW
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
3799 wcW
.lpszMenuName
= NULL
;
3801 if (!ME_ListBoxRegistered
)
3803 wcW
.style
= CS_PARENTDC
| CS_DBLCLKS
| CS_GLOBALCLASS
;
3804 wcW
.lpfnWndProc
= REListWndProc
;
3805 wcW
.lpszClassName
= REListBox20W
;
3806 if (RegisterClassW(&wcW
)) ME_ListBoxRegistered
= TRUE
;
3809 if (!ME_ComboBoxRegistered
)
3811 wcW
.style
= CS_PARENTDC
| CS_DBLCLKS
| CS_GLOBALCLASS
| CS_VREDRAW
| CS_HREDRAW
;
3812 wcW
.lpfnWndProc
= REComboWndProc
;
3813 wcW
.lpszClassName
= REComboBox20W
;
3814 if (RegisterClassW(&wcW
)) ME_ComboBoxRegistered
= TRUE
;
3818 if (ME_ListBoxRegistered
)
3820 if (ME_ComboBoxRegistered
)
3826 int ME_AutoURLDetect(ME_TextEditor
*editor
, WCHAR curChar
)
3846 int curf_ef
, link_ef
, def_ef
;
3847 int cur_prefx
, prefx_cnt
;
3848 int sel_min
, sel_max
;
3851 int URLmin
, URLmax
= 0;
3853 CHARFORMAT2W cur_format
;
3854 CHARFORMAT2W default_format
;
3856 RichEditANSIWndProc(editor
->hWnd
, EM_EXGETSEL
, (WPARAM
) 0, (LPARAM
) &ins_pt
);
3857 sel_min
= ins_pt
.cpMin
;
3858 sel_max
= ins_pt
.cpMax
;
3859 if (sel_min
==sel_max
)
3861 if (sel_min
!=sel_max
)
3862 car_pos
= ME_GetTextLength(editor
)+1;
3863 cur_format
.cbSize
= sizeof(cur_format
);
3864 default_format
.cbSize
= sizeof(default_format
);
3865 RichEditANSIWndProc(editor
->hWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cur_format
);
3866 RichEditANSIWndProc(editor
->hWnd
, EM_GETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
) &default_format
);
3867 link
.cbSize
= sizeof(link
);
3868 link
.dwMask
= CFM_LINK
;
3869 link
.dwEffects
= CFE_LINK
;
3870 curf_ef
= cur_format
.dwEffects
& link
.dwEffects
;
3871 def_ef
= default_format
.dwEffects
& link
.dwEffects
;
3872 link_ef
= link
.dwEffects
& link
.dwEffects
;
3873 if (curf_ef
== link_ef
)
3875 if( curChar
== '\n' || curChar
=='\r' || curChar
==' ')
3877 ME_SetSelection(editor
, car_pos
, car_pos
);
3878 RichEditANSIWndProc(editor
->hWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &default_format
);
3883 if (curf_ef
== def_ef
)
3886 prefx_cnt
= (sizeof(prefixes
)/sizeof(struct prefix_s
))-1;
3887 while (cur_prefx
<=prefx_cnt
)
3891 ft
.lpstrText
= prefixes
[cur_prefx
].text
;
3892 URLmin
=max(0,(car_pos
-prefixes
[cur_prefx
].length
));
3893 URLmax
=max(0, car_pos
);
3894 if ((car_pos
== 0) && (ME_GetTextLength(editor
) != 0))
3896 URLmax
= ME_GetTextLength(editor
)+1;
3898 ft
.chrg
.cpMin
= URLmin
;
3899 ft
.chrg
.cpMax
= URLmax
;
3900 text_pos
=RichEditANSIWndProc(editor
->hWnd
, EM_FINDTEXT
, FR_DOWN
, (LPARAM
)&ft
);
3905 ME_SetCharFormat(editor
, text_pos
, (URLmax
-text_pos
), &link
);
3906 ME_RewrapRepaint(editor
);
3915 static BOOL
isurlspecial(WCHAR c
)
3917 static const WCHAR special_chars
[] = {'.','/','%','@','*','|','\\','+','#',0};
3918 return strchrW( special_chars
, c
) != NULL
;
3922 * This proc takes a selection, and scans it forward in order to select the span
3923 * of a possible URL candidate. A possible URL candidate must start with isalnum
3924 * or one of the following special characters: *|/\+%#@ and must consist entirely
3925 * of the characters allowed to start the URL, plus : (colon) which may occur
3926 * at most once, and not at either end.
3928 * sel_max == -1 indicates scan to end of text.
3930 BOOL
ME_FindNextURLCandidate(ME_TextEditor
*editor
, int sel_min
, int sel_max
,
3931 int * candidate_min
, int * candidate_max
)
3933 ME_DisplayItem
* item
;
3934 ME_DisplayItem
* para
;
3936 BOOL foundColon
= FALSE
;
3937 WCHAR lastAcceptedChar
= '\0';
3939 TRACE("sel_min = %d sel_max = %d\n", sel_min
, sel_max
);
3941 *candidate_min
= *candidate_max
= -1;
3942 item
= ME_FindItemAtOffset(editor
, diRun
, sel_min
, &nStart
);
3943 if (!item
) return FALSE
;
3944 TRACE("nStart = %d\n", nStart
);
3945 para
= ME_GetParagraph(item
);
3946 if (sel_max
== -1) sel_max
= ME_GetTextLength(editor
);
3947 while (item
&& para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
< sel_max
)
3949 ME_DisplayItem
* next_item
;
3951 if (!(item
->member
.run
.nFlags
& MERF_ENDPARA
)) {
3952 /* Find start of candidate */
3953 if (*candidate_min
== -1) {
3954 while (nStart
< ME_StrLen(item
->member
.run
.strText
) &&
3955 !(isalnumW(item
->member
.run
.strText
->szData
[nStart
]) ||
3956 isurlspecial(item
->member
.run
.strText
->szData
[nStart
]))) {
3959 if (nStart
< ME_StrLen(item
->member
.run
.strText
) &&
3960 (isalnumW(item
->member
.run
.strText
->szData
[nStart
]) ||
3961 isurlspecial(item
->member
.run
.strText
->szData
[nStart
]))) {
3962 *candidate_min
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
;
3963 lastAcceptedChar
= item
->member
.run
.strText
->szData
[nStart
];
3968 /* Find end of candidate */
3969 if (*candidate_min
>= 0) {
3970 while (nStart
< ME_StrLen(item
->member
.run
.strText
) &&
3971 (isalnumW(item
->member
.run
.strText
->szData
[nStart
]) ||
3972 isurlspecial(item
->member
.run
.strText
->szData
[nStart
]) ||
3973 (!foundColon
&& item
->member
.run
.strText
->szData
[nStart
] == ':') )) {
3974 if (item
->member
.run
.strText
->szData
[nStart
] == ':') foundColon
= TRUE
;
3975 lastAcceptedChar
= item
->member
.run
.strText
->szData
[nStart
];
3978 if (nStart
< ME_StrLen(item
->member
.run
.strText
) &&
3979 !(isalnumW(item
->member
.run
.strText
->szData
[nStart
]) ||
3980 isurlspecial(item
->member
.run
.strText
->szData
[nStart
]) )) {
3981 *candidate_max
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
;
3983 if (lastAcceptedChar
== ':') (*candidate_max
)--;
3988 /* End of paragraph: skip it if before candidate span, or terminates
3989 current active span */
3990 if (*candidate_min
>= 0) {
3991 *candidate_max
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
;
3992 if (lastAcceptedChar
== ':') (*candidate_max
)--;
3997 /* Reaching this point means no span was found, so get next span */
3998 next_item
= ME_FindItemFwd(item
, diRun
);
4000 if (*candidate_min
>= 0) {
4001 /* There are no further runs, so take end of text as end of candidate */
4002 *candidate_max
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
;
4003 if (lastAcceptedChar
== ':') (*candidate_max
)--;
4008 para
= ME_GetParagraph(item
);
4013 if (*candidate_min
>= 0) {
4014 /* There are no further runs, so take end of text as end of candidate */
4015 *candidate_max
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
;
4016 if (lastAcceptedChar
== ':') (*candidate_max
)--;
4024 * This proc evaluates the selection and returns TRUE if it can be considered an URL
4026 BOOL
ME_IsCandidateAnURL(ME_TextEditor
*editor
, int sel_min
, int sel_max
)
4032 /* Code below depends on these being in decreasing length order! */
4046 LPWSTR bufferW
= NULL
;
4050 if (sel_max
== -1) sel_max
= ME_GetTextLength(editor
);
4051 assert(sel_min
<= sel_max
);
4052 for (i
= 0; i
< sizeof(prefixes
) / sizeof(struct prefix_s
); i
++)
4054 if (sel_max
- sel_min
< prefixes
[i
].length
) continue;
4055 if (bufferW
== NULL
) {
4056 bufferW
= (LPWSTR
)heap_alloc((sel_max
- sel_min
+ 1) * sizeof(WCHAR
));
4058 ME_GetTextW(editor
, bufferW
, sel_min
, min(sel_max
- sel_min
, strlen(prefixes
[i
].text
)), 0);
4059 MultiByteToWideChar(CP_ACP
, 0, prefixes
[i
].text
, -1, bufW
, 32);
4060 if (!lstrcmpW(bufW
, bufferW
))
4071 * This proc walks through the indicated selection and evaluates whether each
4072 * section identified by ME_FindNextURLCandidate and in-between sections have
4073 * their proper CFE_LINK attributes set or unset. If the CFE_LINK attribute is
4074 * not what it is supposed to be, this proc sets or unsets it as appropriate.
4076 * Returns TRUE if at least one section was modified.
4078 BOOL
ME_UpdateLinkAttribute(ME_TextEditor
*editor
, int sel_min
, int sel_max
)
4080 BOOL modified
= FALSE
;
4083 if (sel_max
== -1) sel_max
= ME_GetTextLength(editor
);
4090 if (ME_FindNextURLCandidate(editor
, sel_min
, sel_max
, &cMin
, &cMax
))
4092 /* Section before candidate is not an URL */
4093 beforeURL
[0] = sel_min
;
4094 beforeURL
[1] = cMin
;
4096 if (ME_IsCandidateAnURL(editor
, cMin
, cMax
))
4098 inURL
[0] = cMin
; inURL
[1] = cMax
;
4102 beforeURL
[1] = cMax
;
4103 inURL
[0] = inURL
[1] = -1;
4109 /* No more candidates until end of selection */
4110 beforeURL
[0] = sel_min
;
4111 beforeURL
[1] = sel_max
;
4112 inURL
[0] = inURL
[1] = -1;
4116 if (beforeURL
[0] < beforeURL
[1])
4118 /* CFE_LINK effect should be consistently unset */
4119 link
.cbSize
= sizeof(link
);
4120 ME_GetCharFormat(editor
, beforeURL
[0], beforeURL
[1], &link
);
4121 if (!(link
.dwMask
& CFM_LINK
) || (link
.dwEffects
& CFE_LINK
))
4123 /* CFE_LINK must be unset from this range */
4124 memset(&link
, 0, sizeof(CHARFORMAT2W
));
4125 link
.cbSize
= sizeof(link
);
4126 link
.dwMask
= CFM_LINK
;
4128 ME_SetCharFormat(editor
, beforeURL
[0], beforeURL
[1] - beforeURL
[0], &link
);
4132 if (inURL
[0] < inURL
[1])
4134 /* CFE_LINK effect should be consistently set */
4135 link
.cbSize
= sizeof(link
);
4136 ME_GetCharFormat(editor
, inURL
[0], inURL
[1], &link
);
4137 if (!(link
.dwMask
& CFM_LINK
) || !(link
.dwEffects
& CFE_LINK
))
4139 /* CFE_LINK must be set on this range */
4140 memset(&link
, 0, sizeof(CHARFORMAT2W
));
4141 link
.cbSize
= sizeof(link
);
4142 link
.dwMask
= CFM_LINK
;
4143 link
.dwEffects
= CFE_LINK
;
4144 ME_SetCharFormat(editor
, inURL
[0], inURL
[1] - inURL
[0], &link
);
4148 } while (sel_min
< sel_max
);
4152 void ME_UpdateSelectionLinkAttribute(ME_TextEditor
*editor
)
4154 ME_DisplayItem
* startPara
, * endPara
;
4155 ME_DisplayItem
* item
;
4159 ME_GetSelection(editor
, &from
, &to
);
4160 if (from
> to
) from
^= to
, to
^=from
, from
^= to
;
4161 startPara
= NULL
; endPara
= NULL
;
4163 /* Find paragraph previous to the one that contains start cursor */
4164 item
= ME_FindItemAtOffset(editor
, diRun
, from
, &dummy
);
4166 startPara
= ME_FindItemBack(item
, diParagraph
);
4167 item
= ME_FindItemBack(startPara
, diParagraph
);
4168 if (item
) startPara
= item
;
4171 /* Find paragraph that contains end cursor */
4172 item
= ME_FindItemAtOffset(editor
, diRun
, to
, &dummy
);
4174 endPara
= ME_FindItemFwd(item
, diParagraph
);
4177 if (startPara
&& endPara
) {
4178 ME_UpdateLinkAttribute(editor
,
4179 startPara
->member
.para
.nCharOfs
,
4180 endPara
->member
.para
.nCharOfs
);
4181 } else if (startPara
) {
4182 ME_UpdateLinkAttribute(editor
,
4183 startPara
->member
.para
.nCharOfs
,