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
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 API implementation status:
26 Messages (ANSI versions not done yet)
27 + EM_AUTOURLDETECT 2.0
38 + EM_FINDTEXT (only FR_DOWN flag implemented)
39 + EM_FINDTEXTEX (only FR_DOWN flag implemented)
43 + EM_GETAUTOURLDETECT 2.0
44 - EM_GETBIDIOPTIONS 3.0
45 - EM_GETCHARFORMAT (partly done)
48 + EM_GETFIRSTVISIBLELINE (can be optimized if needed)
49 - EM_GETIMECOLOR 1.0asian
50 - EM_GETIMECOMPMODE 2.0
51 - EM_GETIMEOPTIONS 1.0asian
53 - EM_GETLANGOPTIONS 2.0
56 + EM_GETLINECOUNT returns number of rows, not of paragraphs
61 + EM_GETPASSWORDCHAR 2.0
62 - EM_GETPUNCTUATION 1.0asian
66 + EM_GETSELTEXT (ANSI&Unicode)
67 + EM_GETSCROLLPOS 3.0 (only Y value valid)
70 + EM_GETTEXTLENGTHEX (GTL_PRECISE unimplemented)
72 ? + EM_GETTEXTRANGE (ANSI&Unicode)
73 - EM_GETTYPOGRAPHYOPTIONS 3.0
76 - EM_GETWORDBREAKPROCEX
77 - EM_GETWORDWRAPMODE 1.0asian
80 + EM_LIMITTEXT (Also called EM_SETLIMITTEXT)
89 + EM_REPLACESEL (proper style?) ANSI&Unicode
93 - EM_SETBIDIOPTIONS 3.0
95 + EM_SETCHARFORMAT (partly done, no ANSI)
97 + EM_SETEVENTMASK (few notifications supported)
99 - EM_SETIMECOLOR 1.0asian
100 - EM_SETIMEOPTIONS 1.0asian
101 - EM_SETLANGOPTIONS 2.0
103 + EM_SETMODIFY (not sure if implementation is correct)
105 + EM_SETOPTIONS (partially implemented)
108 + EM_SETPASSWORDCHAR 2.0
109 - EM_SETPUNCTUATION 1.0asian
110 + EM_SETREADONLY no beep on modification attempt
112 + EM_SETRECTNP (EM_SETRECT without repainting)
114 + EM_SETSCROLLPOS 3.0
117 + EM_SETTEXTEX 3.0 (no rich text insertion handling, proper style?)
119 - EM_SETTYPOGRAPHYOPTIONS 3.0
120 + EM_SETUNDOLIMIT 2.0
121 + EM_SETWORDBREAKPROC (used only for word movement at the moment)
122 - EM_SETWORDBREAKPROCEX
123 - EM_SETWORDWRAPMODE 1.0asian
125 + EM_SHOWSCROLLBAR 2.0
126 - EM_STOPGROUPTYPING 2.0
134 + WM_GETDLGCODE (the current implementation is incomplete)
135 + WM_GETTEXT (ANSI&Unicode)
136 + WM_GETTEXTLENGTH (ANSI version sucks)
139 + WM_SETTEXT (resets undo stack !) (proper style?) ANSI&Unicode
141 - WM_STYLECHANGED (things like read-only flag)
146 * EN_CHANGE (sent from the wrong place)
163 * EN_UPDATE (sent from the wrong place)
171 + ES_DISABLENOSCROLL (scrollbar is always visible)
172 - ES_EX_NOCALLOLEINIT
174 - ES_MULTILINE (currently single line controls aren't supported)
176 - ES_READONLY (I'm not sure if beeping is the proper behaviour)
182 - ES_WANTRETURN (don't know how to do WM_GETDLGCODE part)
189 * RICHED20 TODO (incomplete):
191 * - 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
230 #include "textserv.h"
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};
248 HANDLE me_heap
= NULL
;
250 static BOOL ME_ListBoxRegistered
= FALSE
;
251 static BOOL ME_ComboBoxRegistered
= FALSE
;
253 static inline int is_version_nt(void)
255 return !(GetVersion() & 0x80000000);
258 static ME_TextBuffer
*ME_MakeText(void) {
260 ME_TextBuffer
*buf
= ALLOC_OBJ(ME_TextBuffer
);
262 ME_DisplayItem
*p1
= ME_MakeDI(diTextStart
);
263 ME_DisplayItem
*p2
= ME_MakeDI(diTextEnd
);
269 p1
->member
.para
.next_para
= p2
;
270 p2
->member
.para
.prev_para
= p1
;
271 p2
->member
.para
.nCharOfs
= 0;
275 buf
->pCharStyle
= NULL
;
281 static LRESULT
ME_StreamInText(ME_TextEditor
*editor
, DWORD dwFormat
, ME_InStream
*stream
, ME_Style
*style
)
283 WCHAR wszText
[STREAMIN_BUFFER_SIZE
+1];
286 TRACE("%08x %p\n", dwFormat
, stream
);
293 ME_StreamInFill(stream
);
294 if (stream
->editstream
->dwError
)
300 if (!(dwFormat
& SF_UNICODE
))
302 /* FIXME? this is doomed to fail on true MBCS like UTF-8, luckily they're unlikely to be used as CP_ACP */
303 nWideChars
= MultiByteToWideChar(CP_ACP
, 0, stream
->buffer
, stream
->dwSize
, wszText
, STREAMIN_BUFFER_SIZE
);
308 nWideChars
= stream
->dwSize
>> 1;
309 pText
= (WCHAR
*)stream
->buffer
;
312 ME_InsertTextFromCursor(editor
, 0, pText
, nWideChars
, style
);
313 if (stream
->dwSize
== 0)
317 ME_CommitUndo(editor
);
318 ME_UpdateRepaint(editor
);
322 static void ME_RTFCharAttrHook(RTF_Info
*info
)
325 fmt
.cbSize
= sizeof(fmt
);
329 switch(info
->rtfMinor
)
332 /* FIXME add more flags once they're implemented */
333 fmt
.dwMask
= CFM_BOLD
| CFM_ITALIC
| CFM_UNDERLINE
| CFM_STRIKEOUT
| CFM_COLOR
| CFM_BACKCOLOR
| CFM_SIZE
| CFM_WEIGHT
;
334 fmt
.dwEffects
= CFE_AUTOCOLOR
| CFE_AUTOBACKCOLOR
;
335 fmt
.yHeight
= 12*20; /* 12pt */
339 fmt
.dwMask
= CFM_BOLD
;
340 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
343 fmt
.dwMask
= CFM_ITALIC
;
344 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
347 fmt
.dwMask
= CFM_UNDERLINE
;
348 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
349 fmt
.bUnderlineType
= CFU_CF1UNDERLINE
;
352 fmt
.dwMask
= CFM_UNDERLINE
;
356 fmt
.dwMask
= CFM_STRIKEOUT
;
357 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
361 case rtfSubScrShrink
:
362 case rtfSuperScrShrink
:
364 fmt
.dwMask
= CFM_SUBSCRIPT
|CFM_SUPERSCRIPT
;
365 if (info
->rtfMinor
== rtfSubScrShrink
) fmt
.dwEffects
= CFE_SUBSCRIPT
;
366 if (info
->rtfMinor
== rtfSuperScrShrink
) fmt
.dwEffects
= CFE_SUPERSCRIPT
;
367 if (info
->rtfMinor
== rtfNoSuperSub
) fmt
.dwEffects
= 0;
370 fmt
.dwMask
= CFM_HIDDEN
;
371 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
374 fmt
.dwMask
= CFM_BACKCOLOR
;
376 if (info
->rtfParam
== 0)
377 fmt
.dwEffects
= CFE_AUTOBACKCOLOR
;
378 else if (info
->rtfParam
!= rtfNoParam
)
380 RTFColor
*c
= RTFGetColor(info
, info
->rtfParam
);
381 fmt
.crTextColor
= (c
->rtfCBlue
<<16)|(c
->rtfCGreen
<<8)|(c
->rtfCRed
);
385 fmt
.dwMask
= CFM_COLOR
;
387 if (info
->rtfParam
== 0)
388 fmt
.dwEffects
= CFE_AUTOCOLOR
;
389 else if (info
->rtfParam
!= rtfNoParam
)
391 RTFColor
*c
= RTFGetColor(info
, info
->rtfParam
);
393 fmt
.crTextColor
= (c
->rtfCBlue
<<16)|(c
->rtfCGreen
<<8)|(c
->rtfCRed
);
399 if (info
->rtfParam
!= rtfNoParam
)
401 RTFFont
*f
= RTFGetFont(info
, info
->rtfParam
);
404 MultiByteToWideChar(CP_ACP
, 0, f
->rtfFName
, -1, fmt
.szFaceName
, sizeof(fmt
.szFaceName
)/sizeof(WCHAR
));
405 fmt
.szFaceName
[sizeof(fmt
.szFaceName
)/sizeof(WCHAR
)-1] = '\0';
406 fmt
.bCharSet
= f
->rtfFCharSet
;
407 fmt
.dwMask
= CFM_FACE
| CFM_CHARSET
;
412 fmt
.dwMask
= CFM_SIZE
;
413 if (info
->rtfParam
!= rtfNoParam
)
414 fmt
.yHeight
= info
->rtfParam
*10;
419 RTFFlushOutputBuffer(info
);
420 /* FIXME too slow ? how come ? */
421 style2
= ME_ApplyStyle(info
->style
, &fmt
);
422 ME_ReleaseStyle(info
->style
);
423 info
->style
= style2
;
424 info
->styleChanged
= TRUE
;
428 /* FIXME this function doesn't get any information about context of the RTF tag, which is very bad,
429 the same tags mean different things in different contexts */
430 static void ME_RTFParAttrHook(RTF_Info
*info
)
433 fmt
.cbSize
= sizeof(fmt
);
436 switch(info
->rtfMinor
)
438 case rtfParDef
: /* restores default paragraph attributes */
439 fmt
.dwMask
= PFM_ALIGNMENT
| PFM_TABSTOPS
| PFM_OFFSET
| PFM_STARTINDENT
;
440 fmt
.wAlignment
= PFA_LEFT
;
442 fmt
.dxOffset
= fmt
.dxStartIndent
= 0;
443 RTFFlushOutputBuffer(info
);
444 ME_GetParagraph(info
->editor
->pCursors
[0].pRun
)->member
.para
.bTable
= FALSE
;
448 ME_DisplayItem
*para
;
450 RTFFlushOutputBuffer(info
);
451 para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
452 assert(para
->member
.para
.pCells
);
453 para
->member
.para
.bTable
= TRUE
;
457 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
458 fmt
.dwMask
= PFM_STARTINDENT
| PFM_OFFSET
;
459 fmt
.dxStartIndent
+= info
->rtfParam
+ fmt
.dxOffset
;
460 fmt
.dxOffset
= -info
->rtfParam
;
463 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
464 fmt
.dwMask
= PFM_STARTINDENT
;
465 fmt
.dxStartIndent
= -fmt
.dxOffset
+ info
->rtfParam
;
468 fmt
.dwMask
= PFM_RIGHTINDENT
;
469 fmt
.dxRightIndent
= info
->rtfParam
;
473 fmt
.dwMask
= PFM_ALIGNMENT
;
474 fmt
.wAlignment
= PFA_LEFT
;
477 fmt
.dwMask
= PFM_ALIGNMENT
;
478 fmt
.wAlignment
= PFA_RIGHT
;
481 fmt
.dwMask
= PFM_ALIGNMENT
;
482 fmt
.wAlignment
= PFA_CENTER
;
485 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
486 if (!(fmt
.dwMask
& PFM_TABSTOPS
))
488 fmt
.dwMask
|= PFM_TABSTOPS
;
491 if (fmt
.cTabCount
< MAX_TAB_STOPS
)
492 fmt
.rgxTabs
[fmt
.cTabCount
++] = info
->rtfParam
;
496 RTFFlushOutputBuffer(info
);
497 /* FIXME too slow ? how come ?*/
498 ME_SetSelectionParaFormat(info
->editor
, &fmt
);
502 static void ME_RTFTblAttrHook(RTF_Info
*info
)
504 ME_DisplayItem
*para
;
506 switch (info
->rtfMinor
)
509 RTFFlushOutputBuffer(info
);
510 para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
512 /* Release possibly inherited cell definitions */
513 ME_DestroyTableCellList(para
);
515 para
->member
.para
.pCells
= ALLOC_OBJ(ME_TableCell
);
516 para
->member
.para
.pCells
->nRightBoundary
= 0;
517 para
->member
.para
.pCells
->next
= NULL
;
518 para
->member
.para
.pLastCell
= para
->member
.para
.pCells
;
521 RTFFlushOutputBuffer(info
);
522 para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
524 if (para
->member
.para
.pLastCell
->nRightBoundary
)
526 ME_TableCell
*pCell
= ALLOC_OBJ(ME_TableCell
);
529 para
->member
.para
.pLastCell
->next
= pCell
;
530 para
->member
.para
.pLastCell
= pCell
;
532 para
->member
.para
.pLastCell
->nRightBoundary
= info
->rtfParam
;
537 static void ME_RTFReadHook(RTF_Info
*info
) {
538 switch(info
->rtfClass
)
541 switch(info
->rtfMajor
)
544 if (info
->stackTop
< maxStack
) {
545 memcpy(&info
->stack
[info
->stackTop
].fmt
, &info
->style
->fmt
, sizeof(CHARFORMAT2W
));
546 info
->stack
[info
->stackTop
].codePage
= info
->codePage
;
547 info
->stack
[info
->stackTop
].unicodeLength
= info
->unicodeLength
;
550 info
->styleChanged
= FALSE
;
555 RTFFlushOutputBuffer(info
);
556 if (info
->stackTop
<=1) {
557 info
->rtfClass
= rtfEOF
;
561 assert(info
->stackTop
>= 0);
562 if (info
->styleChanged
)
564 /* FIXME too slow ? how come ? */
565 s
= ME_ApplyStyle(info
->style
, &info
->stack
[info
->stackTop
].fmt
);
566 ME_ReleaseStyle(info
->style
);
568 info
->codePage
= info
->stack
[info
->stackTop
].codePage
;
569 info
->unicodeLength
= info
->stack
[info
->stackTop
].unicodeLength
;
576 switch(info
->rtfMajor
)
579 ME_RTFCharAttrHook(info
);
582 ME_RTFParAttrHook(info
);
585 ME_RTFTblAttrHook(info
);
588 if (info
->rtfMinor
== rtfCell
)
590 RTFFlushOutputBuffer(info
);
591 ME_InsertTableCellFromCursor(info
->editor
, 0);
599 ME_StreamInFill(ME_InStream
*stream
)
601 stream
->editstream
->dwError
= stream
->editstream
->pfnCallback(stream
->editstream
->dwCookie
,
602 (BYTE
*)stream
->buffer
,
603 sizeof(stream
->buffer
),
604 (LONG
*)&stream
->dwSize
);
608 static LRESULT
ME_StreamIn(ME_TextEditor
*editor
, DWORD format
, EDITSTREAM
*stream
)
612 int from
, to
, to2
, nUndoMode
;
613 int nEventMask
= editor
->nEventMask
;
614 ME_InStream inStream
;
616 TRACE("stream==%p hWnd==%p format==0x%X\n", stream
, editor
->hWnd
, (UINT
)format
);
617 editor
->nEventMask
= 0;
619 ME_GetSelection(editor
, &from
, &to
);
620 if ((format
& SFF_SELECTION
) && (editor
->mode
& TM_RICHTEXT
)) {
621 style
= ME_GetSelectionInsertStyle(editor
);
623 ME_InternalDeleteText(editor
, from
, to
-from
);
626 style
= editor
->pBuffer
->pDefaultStyle
;
627 ME_AddRefStyle(style
);
628 SendMessageA(editor
->hWnd
, EM_SETSEL
, 0, 0);
629 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
));
631 ME_ClearTempStyle(editor
);
632 /* FIXME restore default paragraph formatting ! */
636 /* Back up undo mode to a local variable */
637 nUndoMode
= editor
->nUndoMode
;
639 /* Only create an undo if SFF_SELECTION is set */
640 if (!(format
& SFF_SELECTION
))
641 editor
->nUndoMode
= umIgnore
;
643 inStream
.editstream
= stream
;
644 inStream
.editstream
->dwError
= 0;
650 /* Check if it's really RTF, and if it is not, use plain text */
651 ME_StreamInFill(&inStream
);
652 if (!inStream
.editstream
->dwError
)
654 if (strncmp(inStream
.buffer
, "{\\rtf", 5) && strncmp(inStream
.buffer
, "{\\urtf", 6))
662 if (!inStream
.editstream
->dwError
)
664 if (format
& SF_RTF
) {
665 /* setup the RTF parser */
666 memset(&parser
, 0, sizeof parser
);
667 RTFSetEditStream(&parser
, &inStream
);
668 parser
.rtfFormat
= format
&(SF_TEXT
|SF_RTF
);
669 parser
.hwndEdit
= editor
->hWnd
;
670 parser
.editor
= editor
;
671 parser
.style
= style
;
674 RTFSetReadHook(&parser
, ME_RTFReadHook
);
679 RTFFlushOutputBuffer(&parser
);
682 style
= parser
.style
;
684 else if (format
& SF_TEXT
)
685 ME_StreamInText(editor
, format
, &inStream
, style
);
687 ERR("EM_STREAMIN without SF_TEXT or SF_RTF\n");
688 ME_GetSelection(editor
, &to
, &to2
);
689 /* put the cursor at the top */
690 if (!(format
& SFF_SELECTION
))
691 SendMessageA(editor
->hWnd
, EM_SETSEL
, 0, 0);
694 /* Restore saved undo mode */
695 editor
->nUndoMode
= nUndoMode
;
697 /* even if we didn't add an undo, we need to commit anything on the stack */
698 ME_CommitUndo(editor
);
700 /* If SFF_SELECTION isn't set, delete any undos from before we started too */
701 if (!(format
& SFF_SELECTION
))
702 ME_EmptyUndoStack(editor
);
704 ME_ReleaseStyle(style
);
705 editor
->nEventMask
= nEventMask
;
708 ME_UpdateRepaint(editor
);
710 if (!(format
& SFF_SELECTION
)) {
711 ME_ClearTempStyle(editor
);
713 ME_MoveCaret(editor
);
714 ME_SendSelChange(editor
);
715 ME_SendRequestResize(editor
, FALSE
);
721 typedef struct tagME_RTFStringStreamStruct
726 } ME_RTFStringStreamStruct
;
728 static DWORD CALLBACK
ME_ReadFromRTFString(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
730 ME_RTFStringStreamStruct
*pStruct
= (ME_RTFStringStreamStruct
*)dwCookie
;
733 count
= min(cb
, pStruct
->length
- pStruct
->pos
);
734 memmove(lpBuff
, pStruct
->string
+ pStruct
->pos
, count
);
735 pStruct
->pos
+= count
;
741 ME_StreamInRTFString(ME_TextEditor
*editor
, BOOL selection
, char *string
)
744 ME_RTFStringStreamStruct data
;
746 data
.string
= string
;
747 data
.length
= strlen(string
);
749 es
.dwCookie
= (DWORD
)&data
;
750 es
.pfnCallback
= ME_ReadFromRTFString
;
751 ME_StreamIn(editor
, SF_RTF
| (selection
? SFF_SELECTION
: 0), &es
);
756 ME_FindItemAtOffset(ME_TextEditor
*editor
, ME_DIType nItemType
, int nOffset
, int *nItemOffset
)
758 ME_DisplayItem
*item
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
760 while (item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= nOffset
)
761 item
= ME_FindItemFwd(item
, diParagraph
);
766 nOffset
-= item
->member
.para
.nCharOfs
;
767 if (nItemType
== diParagraph
) {
769 *nItemOffset
= nOffset
;
774 item
= ME_FindItemFwd(item
, diRun
);
775 } while (item
&& (item
->member
.run
.nCharOfs
+ ME_StrLen(item
->member
.run
.strText
) <= nOffset
));
777 nOffset
-= item
->member
.run
.nCharOfs
;
779 *nItemOffset
= nOffset
;
786 ME_FindText(ME_TextEditor
*editor
, DWORD flags
, CHARRANGE
*chrg
, const WCHAR
*text
, CHARRANGE
*chrgText
)
788 const int nLen
= lstrlenW(text
);
789 const int nTextLen
= ME_GetTextLength(editor
);
792 ME_DisplayItem
*item
;
793 ME_DisplayItem
*para
;
794 WCHAR wLastChar
= ' ';
796 TRACE("flags==0x%08x, chrg->cpMin==%d, chrg->cpMax==%d text==%s\n",
797 flags
, chrg
->cpMin
, chrg
->cpMax
, debugstr_w(text
));
799 if (flags
& ~(FR_DOWN
| FR_MATCHCASE
| FR_WHOLEWORD
))
800 FIXME("Flags 0x%08x not implemented\n",
801 flags
& ~(FR_DOWN
| FR_MATCHCASE
| FR_WHOLEWORD
));
804 if (chrg
->cpMax
== -1)
807 nMax
= chrg
->cpMax
> nTextLen
? nTextLen
: chrg
->cpMax
;
809 /* when searching up, if cpMin < cpMax, then instead of searching
810 * on [cpMin,cpMax], we search on [0,cpMin], otherwise, search on
811 * [cpMax, cpMin]. The exception is when cpMax is -1, in which
812 * case, it is always bigger than cpMin.
814 if (!(flags
& FR_DOWN
))
818 nMax
= nMin
> nTextLen
? nTextLen
: nMin
;
819 if (nMin
< nSwap
|| chrg
->cpMax
== -1)
825 if (!nLen
|| nMin
< 0 || nMax
< 0 || nMax
< nMin
)
828 chrgText
->cpMin
= chrgText
->cpMax
= -1;
832 if (flags
& FR_DOWN
) /* Forward search */
834 /* If possible, find the character before where the search starts */
835 if ((flags
& FR_WHOLEWORD
) && nMin
)
838 item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
842 chrgText
->cpMin
= chrgText
->cpMax
= -1;
845 wLastChar
= item
->member
.run
.strText
->szData
[nStart
];
849 item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
853 chrgText
->cpMin
= chrgText
->cpMax
= -1;
857 para
= ME_GetParagraph(item
);
859 && para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
+ nLen
<= nMax
)
861 ME_DisplayItem
*pCurItem
= item
;
862 int nCurStart
= nStart
;
865 while (pCurItem
&& ME_CharCompare(pCurItem
->member
.run
.strText
->szData
[nCurStart
+ nMatched
], text
[nMatched
], (flags
& FR_MATCHCASE
)))
867 if ((flags
& FR_WHOLEWORD
) && isalnumW(wLastChar
))
871 if (nMatched
== nLen
)
873 ME_DisplayItem
*pNextItem
= pCurItem
;
874 int nNextStart
= nCurStart
;
877 /* Check to see if next character is a whitespace */
878 if (flags
& FR_WHOLEWORD
)
880 if (nCurStart
+ nMatched
== ME_StrLen(pCurItem
->member
.run
.strText
))
882 pNextItem
= ME_FindItemFwd(pCurItem
, diRun
);
883 nNextStart
= -nMatched
;
887 wNextChar
= pNextItem
->member
.run
.strText
->szData
[nNextStart
+ nMatched
];
891 if (isalnumW(wNextChar
))
895 nStart
+= para
->member
.para
.nCharOfs
+ pCurItem
->member
.run
.nCharOfs
;
898 chrgText
->cpMin
= nStart
;
899 chrgText
->cpMax
= nStart
+ nLen
;
901 TRACE("found at %d-%d\n", nStart
, nStart
+ nLen
);
904 if (nCurStart
+ nMatched
== ME_StrLen(pCurItem
->member
.run
.strText
))
906 pCurItem
= ME_FindItemFwd(pCurItem
, diRun
);
907 para
= ME_GetParagraph(pCurItem
);
908 nCurStart
= -nMatched
;
912 wLastChar
= pCurItem
->member
.run
.strText
->szData
[nCurStart
+ nMatched
];
917 if (nStart
== ME_StrLen(item
->member
.run
.strText
))
919 item
= ME_FindItemFwd(item
, diRun
);
920 para
= ME_GetParagraph(item
);
925 else /* Backward search */
927 /* If possible, find the character after where the search ends */
928 if ((flags
& FR_WHOLEWORD
) && nMax
< nTextLen
- 1)
931 item
= ME_FindItemAtOffset(editor
, diRun
, nEnd
, &nEnd
);
935 chrgText
->cpMin
= chrgText
->cpMax
= -1;
938 wLastChar
= item
->member
.run
.strText
->szData
[nEnd
];
942 item
= ME_FindItemAtOffset(editor
, diRun
, nEnd
, &nEnd
);
946 chrgText
->cpMin
= chrgText
->cpMax
= -1;
950 para
= ME_GetParagraph(item
);
953 && para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nEnd
- nLen
>= nMin
)
955 ME_DisplayItem
*pCurItem
= item
;
959 if (nCurEnd
- nMatched
== 0)
961 pCurItem
= ME_FindItemBack(pCurItem
, diRun
);
962 para
= ME_GetParagraph(pCurItem
);
963 nCurEnd
= ME_StrLen(pCurItem
->member
.run
.strText
) + nMatched
;
966 while (pCurItem
&& ME_CharCompare(pCurItem
->member
.run
.strText
->szData
[nCurEnd
- nMatched
- 1], text
[nLen
- nMatched
- 1], (flags
& FR_MATCHCASE
)))
968 if ((flags
& FR_WHOLEWORD
) && isalnumW(wLastChar
))
972 if (nMatched
== nLen
)
974 ME_DisplayItem
*pPrevItem
= pCurItem
;
975 int nPrevEnd
= nCurEnd
;
978 /* Check to see if previous character is a whitespace */
979 if (flags
& FR_WHOLEWORD
)
981 if (nPrevEnd
- nMatched
== 0)
983 pPrevItem
= ME_FindItemBack(pCurItem
, diRun
);
985 nPrevEnd
= ME_StrLen(pPrevItem
->member
.run
.strText
) + nMatched
;
989 wPrevChar
= pPrevItem
->member
.run
.strText
->szData
[nPrevEnd
- nMatched
- 1];
993 if (isalnumW(wPrevChar
))
997 nStart
= para
->member
.para
.nCharOfs
+ pCurItem
->member
.run
.nCharOfs
+ nCurEnd
- nMatched
;
1000 chrgText
->cpMin
= nStart
;
1001 chrgText
->cpMax
= nStart
+ nLen
;
1003 TRACE("found at %d-%d\n", nStart
, nStart
+ nLen
);
1006 if (nCurEnd
- nMatched
== 0)
1008 pCurItem
= ME_FindItemBack(pCurItem
, diRun
);
1009 /* Don't care about pCurItem becoming NULL here; it's already taken
1010 * care of in the exterior loop condition */
1011 para
= ME_GetParagraph(pCurItem
);
1012 nCurEnd
= ME_StrLen(pCurItem
->member
.run
.strText
) + nMatched
;
1016 wLastChar
= pCurItem
->member
.run
.strText
->szData
[nCurEnd
- nMatched
- 1];
1023 item
= ME_FindItemBack(item
, diRun
);
1024 para
= ME_GetParagraph(item
);
1025 nEnd
= ME_StrLen(item
->member
.run
.strText
);
1029 TRACE("not found\n");
1031 chrgText
->cpMin
= chrgText
->cpMax
= -1;
1037 ME_KeyDown(ME_TextEditor
*editor
, WORD nKey
)
1039 BOOL ctrl_is_down
= GetKeyState(VK_CONTROL
) & 0x8000;
1040 BOOL shift_is_down
= GetKeyState(VK_SHIFT
) & 0x8000;
1052 ME_ArrowKey(editor
, nKey
, shift_is_down
, ctrl_is_down
);
1056 /* FIXME backspace and delete aren't the same, they act different wrt paragraph style of the merged paragraph */
1057 if (GetWindowLongW(editor
->hWnd
, GWL_STYLE
) & ES_READONLY
)
1059 if (ME_IsSelection(editor
))
1060 ME_DeleteSelection(editor
);
1061 else if (nKey
== VK_DELETE
|| ME_ArrowKey(editor
, VK_LEFT
, FALSE
, FALSE
))
1062 ME_DeleteTextAtCursor(editor
, 1, 1);
1065 ME_CommitUndo(editor
);
1066 ME_UpdateRepaint(editor
);
1067 ME_SendRequestResize(editor
, FALSE
);
1077 chf
.cbSize
= sizeof(chf
);
1079 ME_GetSelectionCharFormat(editor
, &chf
);
1080 ME_DumpStyleToBuf(&chf
, buf
);
1081 MessageBoxA(NULL
, buf
, "Style dump", MB_OK
);
1085 ME_CheckCharOffsets(editor
);
1092 static BOOL
ME_ShowContextMenu(ME_TextEditor
*editor
, int x
, int y
)
1097 if(!editor
->lpOleCallback
)
1099 ME_GetSelection(editor
, (int *)&selrange
.cpMin
, (int *)&selrange
.cpMax
);
1100 if(selrange
.cpMin
== selrange
.cpMax
)
1101 seltype
|= SEL_EMPTY
;
1104 /* FIXME: Handle objects */
1105 seltype
|= SEL_TEXT
;
1106 if(selrange
.cpMax
-selrange
.cpMin
> 1)
1107 seltype
|= SEL_MULTICHAR
;
1109 if(SUCCEEDED(IRichEditOleCallback_GetContextMenu(editor
->lpOleCallback
, seltype
, NULL
, &selrange
, &menu
)))
1111 TrackPopupMenu(menu
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, GetParent(editor
->hWnd
), NULL
);
1117 ME_TextEditor
*ME_MakeEditor(HWND hWnd
) {
1118 ME_TextEditor
*ed
= ALLOC_OBJ(ME_TextEditor
);
1122 ed
->bEmulateVersion10
= FALSE
;
1123 ed
->pBuffer
= ME_MakeText();
1125 ME_MakeFirstParagraph(hDC
, ed
->pBuffer
);
1126 ReleaseDC(hWnd
, hDC
);
1127 ed
->bCaretShown
= FALSE
;
1129 ed
->pCursors
= ALLOC_N_OBJ(ME_Cursor
, ed
->nCursors
);
1130 ed
->pCursors
[0].pRun
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diRun
);
1131 ed
->pCursors
[0].nOffset
= 0;
1132 ed
->pCursors
[1].pRun
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diRun
);
1133 ed
->pCursors
[1].nOffset
= 0;
1134 ed
->nLastTotalLength
= ed
->nTotalLength
= 0;
1137 ed
->rgbBackColor
= -1;
1138 ed
->hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
1139 ed
->bCaretAtEnd
= FALSE
;
1141 ed
->nModifyStep
= 0;
1142 ed
->nTextLimit
= TEXT_LIMIT_DEFAULT
;
1143 ed
->pUndoStack
= ed
->pRedoStack
= ed
->pUndoStackBottom
= NULL
;
1144 ed
->nUndoStackSize
= 0;
1145 ed
->nUndoLimit
= STACK_SIZE_DEFAULT
;
1146 ed
->nUndoMode
= umAddToUndo
;
1147 ed
->nParagraphs
= 1;
1148 ed
->nLastSelStart
= ed
->nLastSelEnd
= 0;
1149 ed
->pLastSelStartPara
= ed
->pLastSelEndPara
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diParagraph
);
1150 ed
->nZoomNumerator
= ed
->nZoomDenominator
= 0;
1152 ed
->bHideSelection
= FALSE
;
1153 ed
->nInvalidOfs
= -1;
1154 ed
->pfnWordBreak
= NULL
;
1155 ed
->lpOleCallback
= NULL
;
1156 ed
->mode
= TM_RICHTEXT
| TM_MULTILEVELUNDO
| TM_MULTICODEPAGE
;
1157 ed
->AutoURLDetect_bEnable
= FALSE
;
1158 GetClientRect(hWnd
, &ed
->rcFormat
);
1159 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
1161 ed
->pFontCache
[i
].nRefs
= 0;
1162 ed
->pFontCache
[i
].nAge
= 0;
1163 ed
->pFontCache
[i
].hFont
= NULL
;
1166 ME_CheckCharOffsets(ed
);
1168 if (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_PASSWORD
)
1169 ed
->cPasswordMask
= '*';
1171 ed
->cPasswordMask
= 0;
1176 typedef struct tagME_GlobalDestStruct
1180 } ME_GlobalDestStruct
;
1182 static DWORD CALLBACK
ME_ReadFromHGLOBALUnicode(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
1184 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
1189 pDest
= (WORD
*)lpBuff
;
1190 pSrc
= (WORD
*)GlobalLock(pData
->hData
);
1191 for (i
= 0; i
<cb
&& pSrc
[pData
->nLength
+i
]; i
++) {
1192 pDest
[i
] = pSrc
[pData
->nLength
+i
];
1194 pData
->nLength
+= i
;
1196 GlobalUnlock(pData
->hData
);
1200 static DWORD CALLBACK
ME_ReadFromHGLOBALRTF(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
1202 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
1207 pSrc
= (BYTE
*)GlobalLock(pData
->hData
);
1208 for (i
= 0; i
<cb
&& pSrc
[pData
->nLength
+i
]; i
++) {
1209 pDest
[i
] = pSrc
[pData
->nLength
+i
];
1211 pData
->nLength
+= i
;
1213 GlobalUnlock(pData
->hData
);
1218 void ME_DestroyEditor(ME_TextEditor
*editor
)
1220 ME_DisplayItem
*pFirst
= editor
->pBuffer
->pFirst
;
1221 ME_DisplayItem
*p
= pFirst
, *pNext
= NULL
;
1224 ME_ClearTempStyle(editor
);
1225 ME_EmptyUndoStack(editor
);
1228 ME_DestroyDisplayItem(p
);
1231 ME_ReleaseStyle(editor
->pBuffer
->pDefaultStyle
);
1232 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
1234 if (editor
->pFontCache
[i
].hFont
)
1235 DeleteObject(editor
->pFontCache
[i
].hFont
);
1237 DeleteObject(editor
->hbrBackground
);
1238 if(editor
->lpOleCallback
)
1239 IUnknown_Release(editor
->lpOleCallback
);
1241 FREE_OBJ(editor
->pBuffer
);
1242 FREE_OBJ(editor
->pCursors
);
1247 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
1252 case DLL_PROCESS_ATTACH
:
1253 DisableThreadLibraryCalls(hinstDLL
);
1254 me_heap
= HeapCreate (0, 0x10000, 0);
1255 if (!ME_RegisterEditorClass(hinstDLL
)) return FALSE
;
1259 case DLL_PROCESS_DETACH
:
1260 UnregisterClassW(RichEdit20W
, 0);
1261 UnregisterClassW(RichEdit50W
, 0);
1262 UnregisterClassA("RichEdit20A", 0);
1263 UnregisterClassA("RichEdit50A", 0);
1264 if (ME_ListBoxRegistered
)
1265 UnregisterClassW(REListBox20W
, 0);
1266 if (ME_ComboBoxRegistered
)
1267 UnregisterClassW(REComboBox20W
, 0);
1269 HeapDestroy (me_heap
);
1277 #define UNSUPPORTED_MSG(e) \
1279 FIXME(#e ": stub\n"); \
1280 return DefWindowProcW(hWnd, msg, wParam, lParam);
1282 static const char * const edit_messages
[] = {
1311 "EM_SETPASSWORDCHAR",
1312 "EM_EMPTYUNDOBUFFER",
1313 "EM_GETFIRSTVISIBLELINE",
1315 "EM_SETWORDBREAKPROC",
1316 "EM_GETWORDBREAKPROC",
1317 "EM_GETPASSWORDCHAR",
1325 static const char * const richedit_messages
[] = {
1330 "EM_EXLINEFROMCHAR",
1336 "EM_GETOLEINTERFACE",
1346 "EM_SETOLECALLBACK",
1348 "EM_SETTARGETDEVICE",
1356 "EM_GETWORDBREAKPROCEX",
1357 "EM_SETWORDBREAKPROCEX",
1359 "EM_UNKNOWN_USER_83",
1364 "EM_STOPGROUPTYPING",
1368 "EM_GETAUTOURLDETECT",
1371 "EM_GETTEXTLENGTHEX",
1374 "EM_UNKNOWN_USER_98",
1375 "EM_UNKNOWN_USER_99",
1376 "EM_SETPUNCTUATION",
1377 "EM_GETPUNCTUATION",
1378 "EM_SETWORDWRAPMODE",
1379 "EM_GETWORDWRAPMODE",
1385 "EM_UNKNOWN_USER_109",
1386 "EM_UNKNOWN_USER_110",
1387 "EM_UNKNOWN_USER_111",
1388 "EM_UNKNOWN_USER_112",
1389 "EM_UNKNOWN_USER_113",
1390 "EM_UNKNOWN_USER_114",
1391 "EM_UNKNOWN_USER_115",
1392 "EM_UNKNOWN_USER_116",
1393 "EM_UNKNOWN_USER_117",
1394 "EM_UNKNOWN_USER_118",
1395 "EM_UNKNOWN_USER_119",
1396 "EM_SETLANGOPTIONS",
1397 "EM_GETLANGOPTIONS",
1398 "EM_GETIMECOMPMODE",
1402 "EM_SETIMEMODEBIAS",
1407 get_msg_name(UINT msg
)
1409 if (msg
>= EM_GETSEL
&& msg
<= EM_CHARFROMPOS
)
1410 return edit_messages
[msg
- EM_GETSEL
];
1411 if (msg
>= EM_CANPASTE
&& msg
<= EM_GETIMEMODEBIAS
)
1412 return richedit_messages
[msg
- EM_CANPASTE
];
1416 static LRESULT
RichEditWndProc_common(HWND hWnd
, UINT msg
, WPARAM wParam
,
1417 LPARAM lParam
, BOOL unicode
)
1419 ME_TextEditor
*editor
= (ME_TextEditor
*)GetWindowLongPtrW(hWnd
, 0);
1421 TRACE("hwnd %p msg %04x (%s) %x %lx, unicode %d\n",
1422 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
, unicode
);
1424 if (!editor
&& msg
!= WM_NCCREATE
&& msg
!= WM_NCDESTROY
) {
1425 ERR("called with invalid hWnd %p - application bug?\n", hWnd
);
1431 UNSUPPORTED_MSG(EM_DISPLAYBAND
)
1432 UNSUPPORTED_MSG(EM_FINDWORDBREAK
)
1433 UNSUPPORTED_MSG(EM_FMTLINES
)
1434 UNSUPPORTED_MSG(EM_FORMATRANGE
)
1435 UNSUPPORTED_MSG(EM_GETBIDIOPTIONS
)
1436 UNSUPPORTED_MSG(EM_GETEDITSTYLE
)
1437 UNSUPPORTED_MSG(EM_GETIMECOMPMODE
)
1438 /* UNSUPPORTED_MSG(EM_GETIMESTATUS) missing in Wine headers */
1439 UNSUPPORTED_MSG(EM_GETLANGOPTIONS
)
1440 /* UNSUPPORTED_MSG(EM_GETOLEINTERFACE) separate stub */
1441 UNSUPPORTED_MSG(EM_GETREDONAME
)
1442 UNSUPPORTED_MSG(EM_GETTEXTMODE
)
1443 UNSUPPORTED_MSG(EM_GETTYPOGRAPHYOPTIONS
)
1444 UNSUPPORTED_MSG(EM_GETUNDONAME
)
1445 UNSUPPORTED_MSG(EM_GETWORDBREAKPROCEX
)
1446 UNSUPPORTED_MSG(EM_PASTESPECIAL
)
1447 UNSUPPORTED_MSG(EM_SELECTIONTYPE
)
1448 UNSUPPORTED_MSG(EM_SETBIDIOPTIONS
)
1449 UNSUPPORTED_MSG(EM_SETEDITSTYLE
)
1450 UNSUPPORTED_MSG(EM_SETFONTSIZE
)
1451 UNSUPPORTED_MSG(EM_SETLANGOPTIONS
)
1452 UNSUPPORTED_MSG(EM_SETPALETTE
)
1453 UNSUPPORTED_MSG(EM_SETTABSTOPS
)
1454 UNSUPPORTED_MSG(EM_SETTARGETDEVICE
)
1455 UNSUPPORTED_MSG(EM_SETTYPOGRAPHYOPTIONS
)
1456 UNSUPPORTED_MSG(EM_SETWORDBREAKPROCEX
)
1457 UNSUPPORTED_MSG(WM_STYLECHANGING
)
1458 UNSUPPORTED_MSG(WM_STYLECHANGED
)
1459 /* UNSUPPORTED_MSG(WM_UNICHAR) FIXME missing in Wine headers */
1461 /* Messages specific to Richedit controls */
1464 return ME_StreamIn(editor
, wParam
, (EDITSTREAM
*)lParam
);
1466 return ME_StreamOut(editor
, wParam
, (EDITSTREAM
*)lParam
);
1469 UINT code
= DLGC_WANTCHARS
|DLGC_WANTARROWS
;
1470 if(lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
1472 int vk
= (int)((LPMSG
)lParam
)->wParam
;
1473 /* if style says we want return key */
1474 if((vk
== VK_RETURN
) && (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_WANTRETURN
))
1476 code
|= DLGC_WANTMESSAGE
;
1478 /* we always handle ctrl-tab */
1479 if((vk
== VK_TAB
) && (GetKeyState(VK_CONTROL
) & 0x8000))
1481 code
|= DLGC_WANTMESSAGE
;
1488 CREATESTRUCTW
*pcs
= (CREATESTRUCTW
*)lParam
;
1489 TRACE("WM_NCCREATE: style 0x%08x\n", pcs
->style
);
1490 editor
= ME_MakeEditor(hWnd
);
1491 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)editor
);
1494 case EM_EMPTYUNDOBUFFER
:
1495 ME_EmptyUndoStack(editor
);
1499 /* Note: wParam/lParam can be NULL */
1501 PUINT pfrom
= wParam
? (PUINT
)wParam
: &from
;
1502 PUINT pto
= lParam
? (PUINT
)lParam
: &to
;
1503 ME_GetSelection(editor
, (int *)pfrom
, (int *)pto
);
1504 if ((*pfrom
|*pto
) & 0xFFFF0000)
1506 return MAKELONG(*pfrom
,*pto
);
1510 CHARRANGE
*pRange
= (CHARRANGE
*)lParam
;
1511 ME_GetSelection(editor
, (int *)&pRange
->cpMin
, (int *)&pRange
->cpMax
);
1512 TRACE("EM_EXGETSEL = (%d,%d)\n", pRange
->cpMin
, pRange
->cpMax
);
1515 case EM_SETUNDOLIMIT
:
1517 if ((int)wParam
< 0)
1518 editor
->nUndoLimit
= STACK_SIZE_DEFAULT
;
1520 editor
->nUndoLimit
= min(wParam
, STACK_SIZE_MAX
);
1521 /* Setting a max stack size keeps wine from getting killed
1522 for hogging memory. Windows allocates all this memory at once, so
1523 no program would realistically set a value above our maxiumum. */
1524 return editor
->nUndoLimit
;
1527 return editor
->pUndoStack
!= NULL
;
1529 return editor
->pRedoStack
!= NULL
;
1530 case WM_UNDO
: /* FIXME: actually not the same */
1539 /* these flags are equivalent to the ES_* counterparts */
1540 DWORD mask
= ECO_VERTICAL
| ECO_AUTOHSCROLL
| ECO_AUTOVSCROLL
|
1541 ECO_NOHIDESEL
| ECO_READONLY
| ECO_WANTRETURN
;
1542 DWORD settings
= GetWindowLongW(hWnd
, GWL_STYLE
) & mask
;
1548 /* these flags are equivalent to ES_* counterparts
1549 * ECO_READONLY is already implemented in the code, only requires
1550 * setting the bit to work
1552 DWORD mask
= ECO_VERTICAL
| ECO_AUTOHSCROLL
| ECO_AUTOVSCROLL
|
1553 ECO_NOHIDESEL
| ECO_READONLY
| ECO_WANTRETURN
;
1554 DWORD raw
= GetWindowLongW(hWnd
, GWL_STYLE
);
1555 DWORD settings
= mask
& raw
;
1571 SetWindowLongW(hWnd
, GWL_STYLE
, (raw
& ~mask
) | (settings
& mask
));
1573 if (lParam
& ECO_AUTOWORDSELECTION
)
1574 FIXME("ECO_AUTOWORDSELECTION not implemented yet!\n");
1575 if (lParam
& ECO_SELECTIONBAR
)
1576 FIXME("ECO_SELECTIONBAR not implemented yet!\n");
1577 if (lParam
& ECO_VERTICAL
)
1578 FIXME("ECO_VERTICAL not implemented yet!\n");
1579 if (lParam
& ECO_AUTOHSCROLL
)
1580 FIXME("ECO_AUTOHSCROLL not implemented yet!\n");
1581 if (lParam
& ECO_AUTOVSCROLL
)
1582 FIXME("ECO_AUTOVSCROLL not implemented yet!\n");
1583 if (lParam
& ECO_NOHIDESEL
)
1584 FIXME("ECO_NOHIDESEL not implemented yet!\n");
1585 if (lParam
& ECO_WANTRETURN
)
1586 FIXME("ECO_WANTRETURN not implemented yet!\n");
1592 ME_InvalidateSelection(editor
);
1593 ME_SetSelection(editor
, wParam
, lParam
);
1594 ME_InvalidateSelection(editor
);
1595 ME_SendSelChange(editor
);
1598 case EM_SETSCROLLPOS
:
1600 POINT
*point
= (POINT
*)lParam
;
1601 ME_ScrollAbs(editor
, point
->y
);
1604 case EM_AUTOURLDETECT
:
1606 if (wParam
==1 || wParam
==0)
1608 editor
->AutoURLDetect_bEnable
= (BOOL
)wParam
;
1611 return E_INVALIDARG
;
1613 case EM_GETAUTOURLDETECT
:
1615 return editor
->AutoURLDetect_bEnable
;
1620 CHARRANGE range
= *(CHARRANGE
*)lParam
;
1622 TRACE("EM_EXSETSEL (%d,%d)\n", range
.cpMin
, range
.cpMax
);
1624 ME_InvalidateSelection(editor
);
1625 end
= ME_SetSelection(editor
, range
.cpMin
, range
.cpMax
);
1626 ME_InvalidateSelection(editor
);
1627 ME_SendSelChange(editor
);
1631 case EM_SHOWSCROLLBAR
:
1633 ShowScrollBar(editor
->hWnd
, wParam
, lParam
);
1639 SETTEXTEX
*pStruct
= (SETTEXTEX
*)wParam
;
1643 int oldModify
= editor
->nModifyStep
;
1645 if (!pStruct
) return 0;
1647 TRACE("EM_SETTEXTEX - %s, flags %d, cp %d\n",
1648 pStruct
->codepage
== 1200 ? debugstr_w((LPCWSTR
)lParam
) : debugstr_a((LPCSTR
)lParam
),
1649 pStruct
->flags
, pStruct
->codepage
);
1651 /* FIXME: make use of pStruct->codepage in the to unicode translation */
1652 wszText
= lParam
? ME_ToUnicode(pStruct
->codepage
== 1200, (void *)lParam
) : NULL
;
1653 len
= wszText
? lstrlenW(wszText
) : 0;
1655 /* FIXME: this should support RTF strings too, according to MSDN */
1656 if (pStruct
->flags
& ST_SELECTION
) {
1657 ME_GetSelection(editor
, &from
, &to
);
1658 style
= ME_GetSelectionInsertStyle(editor
);
1659 ME_InternalDeleteText(editor
, from
, to
- from
);
1660 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, style
);
1661 ME_ReleaseStyle(style
);
1664 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
));
1665 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, editor
->pBuffer
->pDefaultStyle
);
1668 ME_CommitUndo(editor
);
1669 if (!(pStruct
->flags
& ST_KEEPUNDO
))
1671 editor
->nModifyStep
= oldModify
;
1672 ME_EmptyUndoStack(editor
);
1674 ME_UpdateRepaint(editor
);
1677 case EM_SETBKGNDCOLOR
:
1679 LRESULT lColor
= ME_GetBackColor(editor
);
1680 if (editor
->rgbBackColor
!= -1)
1681 DeleteObject(editor
->hbrBackground
);
1684 editor
->rgbBackColor
= -1;
1685 editor
->hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
1689 editor
->rgbBackColor
= lParam
;
1690 editor
->hbrBackground
= CreateSolidBrush(editor
->rgbBackColor
);
1692 if (editor
->bRedraw
)
1694 InvalidateRect(hWnd
, NULL
, TRUE
);
1700 return editor
->nModifyStep
== 0 ? 0 : 1;
1704 editor
->nModifyStep
= 1;
1706 editor
->nModifyStep
= 0;
1710 case EM_SETREADONLY
:
1712 long nStyle
= GetWindowLongW(hWnd
, GWL_STYLE
);
1714 nStyle
|= ES_READONLY
;
1716 nStyle
&= ~ES_READONLY
;
1717 SetWindowLongW(hWnd
, GWL_STYLE
, nStyle
);
1720 case EM_SETEVENTMASK
:
1722 DWORD nOldMask
= editor
->nEventMask
;
1724 editor
->nEventMask
= lParam
;
1727 case EM_GETEVENTMASK
:
1728 return editor
->nEventMask
;
1729 case EM_SETCHARFORMAT
:
1731 CHARFORMAT2W buf
, *p
;
1732 BOOL bRepaint
= TRUE
;
1733 p
= ME_ToCF2W(&buf
, (CHARFORMAT2W
*)lParam
);
1734 if (!wParam
|| (editor
->mode
& TM_PLAINTEXT
))
1735 ME_SetDefaultCharFormat(editor
, p
);
1736 else if (wParam
== (SCF_WORD
| SCF_SELECTION
))
1737 FIXME("EM_SETCHARFORMAT: word selection not supported\n");
1738 else if (wParam
== SCF_ALL
)
1739 ME_SetCharFormat(editor
, 0, ME_GetTextLength(editor
), p
);
1742 ME_GetSelection(editor
, &from
, &to
);
1743 bRepaint
= (from
!= to
);
1744 ME_SetSelectionCharFormat(editor
, p
);
1746 editor
->nModifyStep
= 1;
1747 ME_CommitUndo(editor
);
1749 ME_RewrapRepaint(editor
);
1752 case EM_GETCHARFORMAT
:
1754 CHARFORMAT2W tmp
, *dst
= (CHARFORMAT2W
*)lParam
;
1755 if (dst
->cbSize
!= sizeof(CHARFORMATA
) &&
1756 dst
->cbSize
!= sizeof(CHARFORMATW
) &&
1757 dst
->cbSize
!= sizeof(CHARFORMAT2A
) &&
1758 dst
->cbSize
!= sizeof(CHARFORMAT2W
))
1760 tmp
.cbSize
= sizeof(tmp
);
1762 ME_GetDefaultCharFormat(editor
, &tmp
);
1764 ME_GetSelectionCharFormat(editor
, &tmp
);
1765 ME_CopyToCFAny(dst
, &tmp
);
1768 case EM_SETPARAFORMAT
:
1769 ME_SetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
1770 ME_RewrapRepaint(editor
);
1771 ME_CommitUndo(editor
);
1773 case EM_GETPARAFORMAT
:
1774 ME_GetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
1776 case EM_GETFIRSTVISIBLELINE
:
1778 ME_DisplayItem
*p
= editor
->pBuffer
->pFirst
;
1779 int y
= ME_GetYScrollPos(editor
);
1784 p
= ME_FindItemFwd(p
, diStartRowOrParagraphOrEnd
);
1785 if (p
->type
== diTextEnd
)
1787 if (p
->type
== diParagraph
) {
1788 ypara
= p
->member
.para
.nYPos
;
1791 ystart
= ypara
+ p
->member
.row
.nYPos
;
1792 yend
= ystart
+ p
->member
.row
.nHeight
;
1800 case EM_HIDESELECTION
:
1802 editor
->bHideSelection
= (wParam
!= 0);
1803 ME_InvalidateSelection(editor
);
1808 ME_ScrollDown(editor
, lParam
* 8); /* FIXME follow the original */
1809 return TRUE
; /* Should return false if a single line richedit control */
1814 ME_GetSelection(editor
, &from
, &to
);
1815 ME_InternalDeleteText(editor
, from
, to
-from
);
1816 ME_CommitUndo(editor
);
1817 ME_UpdateRepaint(editor
);
1824 LPWSTR wszText
= ME_ToUnicode(unicode
, (void *)lParam
);
1825 size_t len
= lstrlenW(wszText
);
1826 TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText
));
1828 ME_GetSelection(editor
, &from
, &to
);
1829 style
= ME_GetSelectionInsertStyle(editor
);
1830 ME_InternalDeleteText(editor
, from
, to
-from
);
1831 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, style
);
1832 ME_ReleaseStyle(style
);
1833 /* drop temporary style if line end */
1835 * FIXME question: does abc\n mean: put abc,
1836 * clear temp style, put \n? (would require a change)
1838 if (len
>0 && wszText
[len
-1] == '\n')
1839 ME_ClearTempStyle(editor
);
1840 ME_EndToUnicode(unicode
, wszText
);
1841 ME_CommitUndo(editor
);
1843 ME_EmptyUndoStack(editor
);
1844 ME_UpdateRepaint(editor
);
1847 case EM_SCROLLCARET
:
1849 int top
, bottom
; /* row's edges relative to document top */
1851 ME_DisplayItem
*para
, *row
;
1853 nPos
= ME_GetYScrollPos(editor
);
1854 row
= ME_RowStart(editor
->pCursors
[0].pRun
);
1855 para
= ME_GetParagraph(row
);
1856 top
= para
->member
.para
.nYPos
+ row
->member
.row
.nYPos
;
1857 bottom
= top
+ row
->member
.row
.nHeight
;
1859 if (top
< nPos
) /* caret above window */
1860 ME_ScrollAbs(editor
, top
);
1861 else if (nPos
+ editor
->sizeWindow
.cy
< bottom
) /*below*/
1862 ME_ScrollAbs(editor
, bottom
- editor
->sizeWindow
.cy
);
1870 BOOL bRepaint
= LOWORD(lParam
);
1873 wParam
= (WPARAM
)GetStockObject(SYSTEM_FONT
);
1874 GetObjectW((HGDIOBJ
)wParam
, sizeof(LOGFONTW
), &lf
);
1876 ME_CharFormatFromLogFont(hDC
, &lf
, &fmt
);
1877 ReleaseDC(hWnd
, hDC
);
1878 ME_SetCharFormat(editor
, 0, ME_GetTextLength(editor
), &fmt
);
1879 ME_SetDefaultCharFormat(editor
, &fmt
);
1881 ME_CommitUndo(editor
);
1883 ME_RewrapRepaint(editor
);
1888 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
));
1891 TRACE("WM_SETTEXT lParam==%lx\n",lParam
);
1892 if (!unicode
&& !strncmp((char *)lParam
, "{\\rtf", 5))
1894 /* Undocumented: WM_SETTEXT supports RTF text */
1895 ME_StreamInRTFString(editor
, 0, (char *)lParam
);
1899 LPWSTR wszText
= ME_ToUnicode(unicode
, (void *)lParam
);
1900 TRACE("WM_SETTEXT - %s\n", debugstr_w(wszText
)); /* debugstr_w() */
1901 if (lstrlenW(wszText
) > 0)
1903 /* uses default style! */
1904 ME_InsertTextFromCursor(editor
, 0, wszText
, -1, editor
->pBuffer
->pDefaultStyle
);
1906 ME_EndToUnicode(unicode
, wszText
);
1910 TRACE("WM_SETTEXT - NULL\n");
1911 ME_CommitUndo(editor
);
1912 ME_EmptyUndoStack(editor
);
1913 ME_SetSelection(editor
, 0, 0);
1914 ME_UpdateRepaint(editor
);
1919 UINT nRTFFormat
= RegisterClipboardFormatA("Rich Text Format");
1920 if (IsClipboardFormatAvailable(nRTFFormat
))
1922 if (IsClipboardFormatAvailable(CF_UNICODETEXT
))
1930 ME_GlobalDestStruct gds
;
1931 UINT nRTFFormat
= RegisterClipboardFormatA("Rich Text Format");
1934 if (IsClipboardFormatAvailable(nRTFFormat
))
1935 cf
= nRTFFormat
, dwFormat
= SF_RTF
;
1936 else if (IsClipboardFormatAvailable(CF_UNICODETEXT
))
1937 cf
= CF_UNICODETEXT
, dwFormat
= SF_TEXT
|SF_UNICODE
;
1941 if (!OpenClipboard(hWnd
))
1943 gds
.hData
= GetClipboardData(cf
);
1945 es
.dwCookie
= (DWORD
)&gds
;
1946 es
.pfnCallback
= dwFormat
== SF_RTF
? ME_ReadFromHGLOBALRTF
: ME_ReadFromHGLOBALUnicode
;
1947 ME_StreamIn(editor
, dwFormat
|SFF_SELECTION
, &es
);
1955 LPDATAOBJECT dataObj
= NULL
;
1959 if (editor
->cPasswordMask
)
1960 return 0; /* Copying or Cutting masked text isn't allowed */
1962 ME_GetSelection(editor
, (int*)&range
.cpMin
, (int*)&range
.cpMax
);
1963 if(editor
->lpOleCallback
)
1964 hr
= IRichEditOleCallback_GetClipboardData(editor
->lpOleCallback
, &range
, RECO_COPY
, &dataObj
);
1965 if(FAILED(hr
) || !dataObj
)
1966 hr
= ME_GetDataObject(editor
, &range
, &dataObj
);
1968 hr
= OleSetClipboard(dataObj
);
1969 IDataObject_Release(dataObj
);
1971 if (SUCCEEDED(hr
) && msg
== WM_CUT
)
1973 ME_InternalDeleteText(editor
, range
.cpMin
, range
.cpMax
-range
.cpMin
);
1974 ME_CommitUndo(editor
);
1975 ME_UpdateRepaint(editor
);
1979 case WM_GETTEXTLENGTH
:
1980 return ME_GetTextLength(editor
);
1981 case EM_GETTEXTLENGTHEX
:
1982 return ME_GetTextLengthEx(editor
, (GETTEXTLENGTHEX
*)wParam
);
1985 TEXTRANGEW tr
; /* W and A differ only by rng->lpstrText */
1987 tr
.chrg
.cpMax
= wParam
? (wParam
- 1) : 0;
1988 tr
.lpstrText
= (WCHAR
*)lParam
;
1989 return RichEditWndProc_common(hWnd
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
, unicode
);
1993 GETTEXTEX
*ex
= (GETTEXTEX
*)wParam
;
1996 if (ex
->flags
& ~(GT_SELECTION
| GT_USECRLF
))
1997 FIXME("GETTEXTEX flags 0x%08x not supported\n", ex
->flags
& ~(GT_SELECTION
| GT_USECRLF
));
1999 if (ex
->flags
& GT_SELECTION
)
2001 ME_GetSelection(editor
, &nStart
, &nCount
);
2003 nCount
= min(nCount
, ex
->cb
- 1);
2008 nCount
= ex
->cb
- 1;
2010 if (ex
->codepage
== 1200)
2012 nCount
= min(nCount
, ex
->cb
/ sizeof(WCHAR
) - 1);
2013 return ME_GetTextW(editor
, (LPWSTR
)lParam
, nStart
, nCount
, ex
->flags
& GT_USECRLF
);
2017 /* potentially each char may be a CR, why calculate the exact value with O(N) when
2018 we can just take a bigger buffer? :) */
2019 int crlfmul
= (ex
->flags
& GT_USECRLF
) ? 2 : 1;
2020 LPWSTR buffer
= richedit_alloc((crlfmul
*nCount
+ 1) * sizeof(WCHAR
));
2021 DWORD buflen
= ex
->cb
;
2025 buflen
= ME_GetTextW(editor
, buffer
, nStart
, nCount
, ex
->flags
& GT_USECRLF
);
2026 rc
= WideCharToMultiByte(ex
->codepage
, flags
, buffer
, -1, (LPSTR
)lParam
, ex
->cb
, ex
->lpDefaultChar
, ex
->lpUsedDefaultChar
);
2027 if (rc
) rc
--; /* do not count 0 terminator */
2029 richedit_free(buffer
);
2036 TEXTRANGEW tr
; /* W and A differ only by rng->lpstrText */
2037 ME_GetSelection(editor
, &from
, &to
);
2038 tr
.chrg
.cpMin
= from
;
2040 tr
.lpstrText
= (WCHAR
*)lParam
;
2041 return RichEditWndProc_common(hWnd
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
, unicode
);
2043 case EM_GETSCROLLPOS
:
2045 POINT
*point
= (POINT
*)lParam
;
2046 point
->x
= 0; /* FIXME side scrolling not implemented */
2047 point
->y
= ME_GetYScrollPos(editor
);
2050 case EM_GETTEXTRANGE
:
2052 TEXTRANGEW
*rng
= (TEXTRANGEW
*)lParam
;
2053 TRACE("EM_GETTEXTRANGE min=%d max=%d unicode=%d emul1.0=%d length=%d\n",
2054 rng
->chrg
.cpMin
, rng
->chrg
.cpMax
, unicode
,
2055 editor
->bEmulateVersion10
, ME_GetTextLength(editor
));
2057 return ME_GetTextW(editor
, rng
->lpstrText
, rng
->chrg
.cpMin
, rng
->chrg
.cpMax
-rng
->chrg
.cpMin
, editor
->bEmulateVersion10
);
2060 int nLen
= rng
->chrg
.cpMax
-rng
->chrg
.cpMin
;
2061 WCHAR
*p
= ALLOC_N_OBJ(WCHAR
, nLen
+1);
2062 int nChars
= ME_GetTextW(editor
, p
, rng
->chrg
.cpMin
, nLen
, editor
->bEmulateVersion10
);
2063 /* FIXME this is a potential security hole (buffer overrun)
2064 if you know more about wchar->mbyte conversion please explain
2066 WideCharToMultiByte(CP_ACP
, 0, p
, nChars
+1, (char *)rng
->lpstrText
, nLen
+1, NULL
, NULL
);
2073 ME_DisplayItem
*run
;
2074 const unsigned int nMaxChars
= *(WORD
*) lParam
;
2075 unsigned int nEndChars
, nCharsLeft
= nMaxChars
;
2076 char *dest
= (char *) lParam
;
2077 /* rich text editor 1.0 uses \r\n for line end, 2.0 uses just \r;
2078 we need to know how if we have the extra \n or not */
2079 int nLF
= editor
->bEmulateVersion10
;
2081 TRACE("EM_GETLINE: row=%d, nMaxChars=%d (%s)\n", (int) wParam
, nMaxChars
,
2082 unicode
? "Unicode" : "Ansi");
2084 run
= ME_FindRowWithNumber(editor
, wParam
);
2088 while (nCharsLeft
&& (run
= ME_FindItemFwd(run
, diRunOrStartRow
))
2089 && !(run
->member
.run
.nFlags
& MERF_ENDPARA
))
2093 if (run
->type
!= diRun
)
2095 strText
= run
->member
.run
.strText
;
2096 nCopy
= min(nCharsLeft
, strText
->nLen
);
2099 lstrcpynW((LPWSTR
) dest
, strText
->szData
, nCopy
);
2101 nCopy
= WideCharToMultiByte(CP_ACP
, 0, strText
->szData
, nCopy
, dest
,
2102 nCharsLeft
, NULL
, NULL
);
2103 dest
+= nCopy
* (unicode
? sizeof(WCHAR
) : 1);
2104 nCharsLeft
-= nCopy
;
2107 /* append \r\0 (or \r\n\0 in 1.0), space allowing */
2108 nEndChars
= min(nCharsLeft
, 2 + nLF
);
2109 nCharsLeft
-= nEndChars
;
2112 const WCHAR src
[] = {'\r', '\0'};
2113 const WCHAR src10
[] = {'\r', '\n', '\0'};
2114 lstrcpynW((LPWSTR
) dest
, nLF
? src10
: src
, nEndChars
);
2117 lstrcpynA(dest
, nLF
? "\r\n" : "\r", nEndChars
);
2119 TRACE("EM_GETLINE: got %u bytes\n", nMaxChars
- nCharsLeft
);
2121 if (nEndChars
== 2 + nLF
)
2122 return nMaxChars
- nCharsLeft
- 1; /* don't count \0 */
2124 return nMaxChars
- nCharsLeft
;
2126 case EM_GETLINECOUNT
:
2128 ME_DisplayItem
*item
= editor
->pBuffer
->pFirst
->next
;
2131 while (item
!= editor
->pBuffer
->pLast
)
2133 assert(item
->type
== diParagraph
);
2134 nRows
+= item
->member
.para
.nRows
;
2135 item
= item
->member
.para
.next_para
;
2137 TRACE("EM_GETLINECOUNT: nRows==%d\n", nRows
);
2138 return max(1, nRows
);
2140 case EM_LINEFROMCHAR
:
2143 return ME_RowNumberFromCharOfs(editor
, ME_GetCursorOfs(editor
, 1));
2145 return ME_RowNumberFromCharOfs(editor
, wParam
);
2147 case EM_EXLINEFROMCHAR
:
2150 return ME_RowNumberFromCharOfs(editor
, ME_GetCursorOfs(editor
,1));
2152 return ME_RowNumberFromCharOfs(editor
, lParam
);
2156 ME_DisplayItem
*item
, *para
;
2160 item
= ME_FindItemBack(editor
->pCursors
[0].pRun
, diStartRow
);
2162 item
= ME_FindRowWithNumber(editor
, wParam
);
2165 para
= ME_GetParagraph(item
);
2166 item
= ME_FindItemFwd(item
, diRun
);
2167 nCharOfs
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
;
2168 TRACE("EM_LINEINDEX: nCharOfs==%d\n", nCharOfs
);
2173 ME_DisplayItem
*item
, *item_end
;
2174 int nChars
= 0, nThisLineOfs
= 0, nNextLineOfs
= 0;
2176 if (wParam
> ME_GetTextLength(editor
))
2180 FIXME("EM_LINELENGTH: returning number of unselected characters on lines with selection unsupported.\n");
2183 item
= ME_FindItemAtOffset(editor
, diRun
, wParam
, NULL
);
2184 item
= ME_RowStart(item
);
2185 nThisLineOfs
= ME_CharOfsFromRunOfs(editor
, ME_FindItemFwd(item
, diRun
), 0);
2186 item_end
= ME_FindItemFwd(item
, diStartRowOrParagraphOrEnd
);
2187 if (item_end
->type
== diStartRow
)
2188 nNextLineOfs
= ME_CharOfsFromRunOfs(editor
, ME_FindItemFwd(item_end
, diRun
), 0);
2190 nNextLineOfs
= ME_FindItemFwd(item
, diParagraphOrEnd
)->member
.para
.nCharOfs
2191 - (editor
->bEmulateVersion10
?2:1);
2192 nChars
= nNextLineOfs
- nThisLineOfs
;
2193 TRACE("EM_LINELENGTH(%d)==%d\n",wParam
, nChars
);
2196 case EM_EXLIMITTEXT
:
2198 if ((int)lParam
< 0)
2201 editor
->nTextLimit
= 65536;
2203 editor
->nTextLimit
= (int) lParam
;
2209 editor
->nTextLimit
= 65536;
2211 editor
->nTextLimit
= (int) wParam
;
2214 case EM_GETLIMITTEXT
:
2216 return editor
->nTextLimit
;
2220 FINDTEXTA
*ft
= (FINDTEXTA
*)lParam
;
2221 int nChars
= MultiByteToWideChar(CP_ACP
, 0, ft
->lpstrText
, -1, NULL
, 0);
2225 if ((tmp
= ALLOC_N_OBJ(WCHAR
, nChars
)) != NULL
)
2226 MultiByteToWideChar(CP_ACP
, 0, ft
->lpstrText
, -1, tmp
, nChars
);
2227 r
= ME_FindText(editor
, wParam
, &ft
->chrg
, tmp
, NULL
);
2233 FINDTEXTEXA
*ex
= (FINDTEXTEXA
*)lParam
;
2234 int nChars
= MultiByteToWideChar(CP_ACP
, 0, ex
->lpstrText
, -1, NULL
, 0);
2238 if ((tmp
= ALLOC_N_OBJ(WCHAR
, nChars
)) != NULL
)
2239 MultiByteToWideChar(CP_ACP
, 0, ex
->lpstrText
, -1, tmp
, nChars
);
2240 r
= ME_FindText(editor
, wParam
, &ex
->chrg
, tmp
, &ex
->chrgText
);
2246 FINDTEXTW
*ft
= (FINDTEXTW
*)lParam
;
2247 return ME_FindText(editor
, wParam
, &ft
->chrg
, ft
->lpstrText
, NULL
);
2249 case EM_FINDTEXTEXW
:
2251 FINDTEXTEXW
*ex
= (FINDTEXTEXW
*)lParam
;
2252 return ME_FindText(editor
, wParam
, &ex
->chrg
, ex
->lpstrText
, &ex
->chrgText
);
2255 if (!wParam
|| !lParam
)
2257 *(int *)wParam
= editor
->nZoomNumerator
;
2258 *(int *)lParam
= editor
->nZoomDenominator
;
2261 return ME_SetZoom(editor
, wParam
, lParam
);
2262 case EM_CHARFROMPOS
:
2263 return ME_CharFromPos(editor
, ((POINTL
*)lParam
)->x
, ((POINTL
*)lParam
)->y
);
2264 case EM_POSFROMCHAR
:
2266 ME_DisplayItem
*pRun
;
2267 int nCharOfs
, nOffset
, nLength
;
2271 /* detect which API version we're dealing with */
2272 if (wParam
>= 0x40000)
2274 nLength
= ME_GetTextLength(editor
);
2276 if (nCharOfs
< nLength
) {
2277 ME_RunOfsFromCharOfs(editor
, nCharOfs
, &pRun
, &nOffset
);
2278 assert(pRun
->type
== diRun
);
2279 pt
.y
= pRun
->member
.run
.pt
.y
;
2280 pt
.x
= pRun
->member
.run
.pt
.x
+ ME_PointFromChar(editor
, &pRun
->member
.run
, nOffset
);
2281 pt
.y
+= ME_GetParagraph(pRun
)->member
.para
.nYPos
;
2284 pt
.y
= editor
->pBuffer
->pLast
->member
.para
.nYPos
;
2286 if (wParam
>= 0x40000) {
2287 *(POINTL
*)wParam
= pt
;
2289 return MAKELONG( pt
.x
, pt
.y
);
2292 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_HSCROLL
)
2293 { /* Squelch the default horizontal scrollbar it would make */
2294 ShowScrollBar(editor
->hWnd
, SB_HORZ
, FALSE
);
2296 ME_CommitUndo(editor
);
2297 ME_WrapMarkedParagraphs(editor
);
2298 ME_MoveCaret(editor
);
2301 ME_DestroyEditor(editor
);
2302 SetWindowLongPtrW(hWnd
, 0, 0);
2304 case WM_LBUTTONDOWN
:
2306 ME_LButtonDown(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
2308 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
2311 if (GetCapture() == hWnd
)
2312 ME_MouseMove(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
2313 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
2316 if (GetCapture() == hWnd
)
2318 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
2320 case WM_LBUTTONDBLCLK
:
2321 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
2322 ME_SelectWord(editor
);
2324 case WM_CONTEXTMENU
:
2325 if (!ME_ShowContextMenu(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
)))
2329 if (editor
->bRedraw
)
2334 hDC
= BeginPaint(hWnd
, &ps
);
2335 ME_PaintContent(editor
, hDC
, FALSE
, &ps
.rcPaint
);
2336 EndPaint(hWnd
, &ps
);
2340 ME_ShowCaret(editor
);
2341 ME_SendOldNotify(editor
, EN_SETFOCUS
);
2344 ME_HideCaret(editor
);
2345 ME_SendOldNotify(editor
, EN_KILLFOCUS
);
2349 if (editor
->bRedraw
)
2351 HDC hDC
= (HDC
)wParam
;
2353 if (GetUpdateRect(hWnd
,&rc
,TRUE
))
2355 FillRect(hDC
, &rc
, editor
->hbrBackground
);
2361 TRACE("editor wnd command = %d\n", LOWORD(wParam
));
2364 if (ME_KeyDown(editor
, LOWORD(wParam
)))
2372 wstr
= (WCHAR
)wParam
;
2375 CHAR charA
= wParam
;
2376 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &wstr
, 1);
2378 if (editor
->AutoURLDetect_bEnable
)
2379 ME_AutoURLDetect(editor
, wstr
);
2383 case 1: /* Ctrl-A */
2384 ME_SetSelection(editor
, 0, -1);
2386 case 3: /* Ctrl-C */
2387 SendMessageW(editor
->hWnd
, WM_COPY
, 0, 0);
2391 if (GetWindowLongW(editor
->hWnd
, GWL_STYLE
) & ES_READONLY
) {
2392 MessageBeep(MB_ICONERROR
);
2393 return 0; /* FIXME really 0 ? */
2398 case 22: /* Ctrl-V */
2399 SendMessageW(editor
->hWnd
, WM_PASTE
, 0, 0);
2401 case 24: /* Ctrl-X */
2402 SendMessageW(editor
->hWnd
, WM_CUT
, 0, 0);
2404 case 25: /* Ctrl-Y */
2405 SendMessageW(editor
->hWnd
, EM_REDO
, 0, 0);
2407 case 26: /* Ctrl-Z */
2408 SendMessageW(editor
->hWnd
, EM_UNDO
, 0, 0);
2411 if (((unsigned)wstr
)>=' ' || wstr
=='\r' || wstr
=='\t') {
2412 /* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */
2413 ME_Style
*style
= ME_GetInsertStyle(editor
, 0);
2414 ME_SaveTempStyle(editor
);
2415 ME_InsertTextFromCursor(editor
, 0, &wstr
, 1, style
);
2416 ME_ReleaseStyle(style
);
2417 ME_CommitUndo(editor
);
2418 ME_UpdateRepaint(editor
);
2422 case EM_SCROLL
: /* fall through */
2428 origNPos
= ME_GetYScrollPos(editor
);
2431 if (editor
&& editor
->pBuffer
&& editor
->pBuffer
->pDefaultStyle
)
2432 lineHeight
= editor
->pBuffer
->pDefaultStyle
->tm
.tmHeight
;
2433 if (lineHeight
<= 0) lineHeight
= 24;
2435 switch(LOWORD(wParam
))
2438 ME_ScrollUp(editor
,lineHeight
);
2441 ME_ScrollDown(editor
,lineHeight
);
2444 ME_ScrollUp(editor
,editor
->sizeWindow
.cy
);
2447 ME_ScrollDown(editor
,editor
->sizeWindow
.cy
);
2450 case SB_THUMBPOSITION
:
2451 ME_ScrollAbs(editor
,HIWORD(wParam
));
2454 if (msg
== EM_SCROLL
)
2455 return 0x00010000 | (((ME_GetYScrollPos(editor
) - origNPos
)/lineHeight
) & 0xffff);
2461 UINT pulScrollLines
;
2463 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
2464 gcWheelDelta
= -GET_WHEEL_DELTA_WPARAM(wParam
);
2466 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
2468 /* FIXME follow the original */
2469 ME_ScrollDown(editor
,pulScrollLines
* (gcWheelDelta
/ WHEEL_DELTA
) * 8);
2475 *((RECT
*)lParam
) = editor
->rcFormat
;
2483 RECT
*rc
= (RECT
*)lParam
;
2487 editor
->rcFormat
.left
+= rc
->left
;
2488 editor
->rcFormat
.top
+= rc
->top
;
2489 editor
->rcFormat
.right
+= rc
->right
;
2490 editor
->rcFormat
.bottom
+= rc
->bottom
;
2494 editor
->rcFormat
= *rc
;
2499 GetClientRect(hWnd
, &editor
->rcFormat
);
2501 if (msg
!= EM_SETRECTNP
)
2502 ME_RewrapRepaint(editor
);
2505 case EM_REQUESTRESIZE
:
2506 ME_SendRequestResize(editor
, TRUE
);
2509 editor
->bRedraw
= wParam
;
2513 GetClientRect(hWnd
, &editor
->rcFormat
);
2514 ME_RewrapRepaint(editor
);
2515 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2517 case EM_GETOLEINTERFACE
:
2519 LPVOID
*ppvObj
= (LPVOID
*) lParam
;
2520 return CreateIRichEditOle(editor
, ppvObj
);
2522 case EM_GETPASSWORDCHAR
:
2524 return editor
->cPasswordMask
;
2526 case EM_SETOLECALLBACK
:
2527 if(editor
->lpOleCallback
)
2528 IUnknown_Release(editor
->lpOleCallback
);
2529 editor
->lpOleCallback
= (LPRICHEDITOLECALLBACK
)lParam
;
2530 if(editor
->lpOleCallback
)
2531 IUnknown_AddRef(editor
->lpOleCallback
);
2533 case EM_GETWORDBREAKPROC
:
2534 return (LRESULT
)editor
->pfnWordBreak
;
2535 case EM_SETWORDBREAKPROC
:
2537 EDITWORDBREAKPROCW pfnOld
= editor
->pfnWordBreak
;
2539 editor
->pfnWordBreak
= (EDITWORDBREAKPROCW
)lParam
;
2540 return (LRESULT
)pfnOld
;
2542 case EM_SETTEXTMODE
:
2547 ret
= RichEditWndProc_common(hWnd
, WM_GETTEXTLENGTH
, 0, 0, unicode
);
2550 /*Check for valid wParam*/
2551 if ((((wParam
& TM_RICHTEXT
) && ((wParam
& TM_PLAINTEXT
) << 1))) ||
2552 (((wParam
& TM_MULTILEVELUNDO
) && ((wParam
& TM_SINGLELEVELUNDO
) << 1))) ||
2553 (((wParam
& TM_MULTICODEPAGE
) && ((wParam
& TM_SINGLECODEPAGE
) << 1))))
2557 if (wParam
& (TM_RICHTEXT
| TM_PLAINTEXT
))
2559 mask
|= (TM_RICHTEXT
| TM_PLAINTEXT
);
2560 changes
|= (wParam
& (TM_RICHTEXT
| TM_PLAINTEXT
));
2562 /*FIXME: Currently no support for undo level and code page options*/
2563 editor
->mode
= (editor
->mode
& (~mask
)) | changes
;
2569 case EM_SETPASSWORDCHAR
:
2571 editor
->cPasswordMask
= wParam
;
2572 ME_RewrapRepaint(editor
);
2577 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2582 static LRESULT WINAPI
RichEditWndProcW(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2584 BOOL unicode
= TRUE
;
2586 /* Under Win9x RichEdit20W returns ANSI strings, see the tests. */
2587 if (msg
== WM_GETTEXT
&& (GetVersion() & 0x80000000))
2590 return RichEditWndProc_common(hWnd
, msg
, wParam
, lParam
, unicode
);
2593 static LRESULT WINAPI
RichEditWndProcA(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2595 return RichEditWndProc_common(hWnd
, msg
, wParam
, lParam
, FALSE
);
2598 /******************************************************************
2599 * RichEditANSIWndProc (RICHED20.10)
2601 LRESULT WINAPI
RichEditANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2603 return RichEditWndProcA(hWnd
, msg
, wParam
, lParam
);
2606 /******************************************************************
2607 * RichEdit10ANSIWndProc (RICHED20.9)
2609 LRESULT WINAPI
RichEdit10ANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2613 /* FIXME: this is NOT the same as 2.0 version */
2614 result
= RichEditANSIWndProc(hWnd
, msg
, wParam
, lParam
);
2615 if (msg
== WM_NCCREATE
)
2617 ME_TextEditor
*editor
= (ME_TextEditor
*)GetWindowLongPtrW(hWnd
, 0);
2619 editor
->bEmulateVersion10
= TRUE
;
2620 editor
->pBuffer
->pLast
->member
.para
.nCharOfs
= 2;
2625 void ME_SendOldNotify(ME_TextEditor
*editor
, int nCode
)
2627 HWND hWnd
= editor
->hWnd
;
2628 SendMessageA(GetParent(hWnd
), WM_COMMAND
, (nCode
<<16)|GetWindowLongW(hWnd
, GWLP_ID
), (LPARAM
)hWnd
);
2631 void ME_LinkNotify(ME_TextEditor
*editor
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2634 ME_Cursor tmpCursor
;
2635 int nCharOfs
; /* The start of the clicked text. Absolute character offset */
2640 x
= (short)LOWORD(lParam
);
2641 y
= (short)HIWORD(lParam
);
2642 nCharOfs
= ME_CharFromPos(editor
, x
, y
);
2643 if (nCharOfs
< 0) return;
2645 ME_CursorFromCharOfs(editor
, nCharOfs
, &tmpCursor
);
2646 tmpRun
= &tmpCursor
.pRun
->member
.run
;
2648 if ((tmpRun
->style
->fmt
.dwMask
& CFM_LINK
)
2649 && (tmpRun
->style
->fmt
.dwEffects
& CFE_LINK
))
2650 { /* The clicked run has CFE_LINK set */
2651 info
.nmhdr
.hwndFrom
= editor
->hWnd
;
2652 info
.nmhdr
.idFrom
= GetWindowLongW(editor
->hWnd
, GWLP_ID
);
2653 info
.nmhdr
.code
= EN_LINK
;
2655 info
.wParam
= wParam
;
2656 info
.lParam
= lParam
;
2657 info
.chrg
.cpMin
= ME_CharOfsFromRunOfs(editor
,tmpCursor
.pRun
,0);
2658 info
.chrg
.cpMax
= info
.chrg
.cpMin
+ ME_StrVLen(tmpRun
->strText
);
2659 SendMessageW(GetParent(editor
->hWnd
), WM_NOTIFY
,info
.nmhdr
.idFrom
, (LPARAM
)&info
);
2663 int ME_CountParagraphsBetween(ME_TextEditor
*editor
, int from
, int to
)
2665 ME_DisplayItem
*item
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
2668 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= from
)
2669 item
= item
->member
.para
.next_para
;
2672 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= to
) {
2673 item
= item
->member
.para
.next_para
;
2680 int ME_GetTextW(ME_TextEditor
*editor
, WCHAR
*buffer
, int nStart
, int nChars
, int bCRLF
)
2682 ME_DisplayItem
*item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
2684 WCHAR
*pStart
= buffer
;
2693 int nLen
= ME_StrLen(item
->member
.run
.strText
) - nStart
;
2696 CopyMemory(buffer
, item
->member
.run
.strText
->szData
+ nStart
, sizeof(WCHAR
)*nLen
);
2703 item
= ME_FindItemFwd(item
, diRun
);
2706 while(nChars
&& item
)
2708 int nLen
= ME_StrLen(item
->member
.run
.strText
);
2712 if (item
->member
.run
.nFlags
& MERF_ENDPARA
)
2714 if (!ME_FindItemFwd(item
, diRun
))
2715 /* No '\r' is appended to the last paragraph. */
2725 /* our end paragraph consists of 2 characters now */
2726 if (editor
->bEmulateVersion10
)
2731 CopyMemory(buffer
, item
->member
.run
.strText
->szData
, sizeof(WCHAR
)*nLen
);
2738 TRACE("nWritten=%d, actual=%d\n", nWritten
, buffer
-pStart
);
2742 item
= ME_FindItemFwd(item
, diRun
);
2745 TRACE("nWritten=%d, actual=%d\n", nWritten
, buffer
-pStart
);
2749 static BOOL
ME_RegisterEditorClass(HINSTANCE hInstance
)
2754 wcW
.style
= CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
;
2755 wcW
.lpfnWndProc
= RichEditWndProcW
;
2757 wcW
.cbWndExtra
= sizeof(ME_TextEditor
*);
2758 wcW
.hInstance
= NULL
; /* hInstance would register DLL-local class */
2760 wcW
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
2761 wcW
.hbrBackground
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
2762 wcW
.lpszMenuName
= NULL
;
2764 if (is_version_nt())
2766 wcW
.lpszClassName
= RichEdit20W
;
2767 if (!RegisterClassW(&wcW
)) return FALSE
;
2768 wcW
.lpszClassName
= RichEdit50W
;
2769 if (!RegisterClassW(&wcW
)) return FALSE
;
2773 /* WNDCLASSA/W have the same layout */
2774 wcW
.lpszClassName
= (LPCWSTR
)"RichEdit20W";
2775 if (!RegisterClassA((WNDCLASSA
*)&wcW
)) return FALSE
;
2776 wcW
.lpszClassName
= (LPCWSTR
)"RichEdit50W";
2777 if (!RegisterClassA((WNDCLASSA
*)&wcW
)) return FALSE
;
2780 wcA
.style
= CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
;
2781 wcA
.lpfnWndProc
= RichEditWndProcA
;
2783 wcA
.cbWndExtra
= sizeof(ME_TextEditor
*);
2784 wcA
.hInstance
= NULL
; /* hInstance would register DLL-local class */
2786 wcA
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
2787 wcA
.hbrBackground
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
2788 wcA
.lpszMenuName
= NULL
;
2789 wcA
.lpszClassName
= "RichEdit20A";
2790 if (!RegisterClassA(&wcA
)) return FALSE
;
2791 wcA
.lpszClassName
= "RichEdit50A";
2792 if (!RegisterClassA(&wcA
)) return FALSE
;
2797 LRESULT WINAPI
REComboWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
) {
2798 /* FIXME: Not implemented */
2799 TRACE("hWnd %p msg %04x (%s) %08x %08lx\n",
2800 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
);
2801 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2804 LRESULT WINAPI
REListWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
) {
2805 /* FIXME: Not implemented */
2806 TRACE("hWnd %p msg %04x (%s) %08x %08lx\n",
2807 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
);
2808 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2811 /******************************************************************
2812 * REExtendedRegisterClass (RICHED20.8)
2814 * FIXME undocumented
2815 * Need to check for errors and implement controls and callbacks
2817 LRESULT WINAPI
REExtendedRegisterClass(void)
2822 FIXME("semi stub\n");
2826 wcW
.hInstance
= NULL
;
2829 wcW
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
2830 wcW
.lpszMenuName
= NULL
;
2832 if (!ME_ListBoxRegistered
)
2834 wcW
.style
= CS_PARENTDC
| CS_DBLCLKS
| CS_GLOBALCLASS
;
2835 wcW
.lpfnWndProc
= REListWndProc
;
2836 wcW
.lpszClassName
= REListBox20W
;
2837 if (RegisterClassW(&wcW
)) ME_ListBoxRegistered
= TRUE
;
2840 if (!ME_ComboBoxRegistered
)
2842 wcW
.style
= CS_PARENTDC
| CS_DBLCLKS
| CS_GLOBALCLASS
| CS_VREDRAW
| CS_HREDRAW
;
2843 wcW
.lpfnWndProc
= REComboWndProc
;
2844 wcW
.lpszClassName
= REComboBox20W
;
2845 if (RegisterClassW(&wcW
)) ME_ComboBoxRegistered
= TRUE
;
2849 if (ME_ListBoxRegistered
)
2851 if (ME_ComboBoxRegistered
)
2857 int ME_AutoURLDetect(ME_TextEditor
*editor
, WCHAR curChar
)
2877 int curf_ef
, link_ef
, def_ef
;
2878 int cur_prefx
, prefx_cnt
;
2879 int sel_min
, sel_max
;
2882 int URLmin
, URLmax
= 0;
2885 CHARFORMAT2W cur_format
;
2886 CHARFORMAT2W default_format
;
2888 RichEditANSIWndProc(editor
->hWnd
, EM_EXGETSEL
, (WPARAM
) 0, (LPARAM
) &ins_pt
);
2889 sel_min
= ins_pt
.cpMin
;
2890 sel_max
= ins_pt
.cpMax
;
2891 if (sel_min
==sel_max
)
2893 if (sel_min
!=sel_max
)
2894 car_pos
= ME_GetTextLength(editor
)+1;
2895 cur_format
.cbSize
= sizeof(cur_format
);
2896 default_format
.cbSize
= sizeof(default_format
);
2897 RichEditANSIWndProc(editor
->hWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cur_format
);
2898 RichEditANSIWndProc(editor
->hWnd
, EM_GETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
) &default_format
);
2899 link
.cbSize
= sizeof(link
);
2900 link
.dwMask
= CFM_LINK
;
2901 link
.dwEffects
= CFE_LINK
;
2902 curf_ef
= cur_format
.dwEffects
& link
.dwEffects
;
2903 def_ef
= default_format
.dwEffects
& link
.dwEffects
;
2904 link_ef
= link
.dwEffects
& link
.dwEffects
;
2905 if (curf_ef
== link_ef
)
2907 if( curChar
== '\n' || curChar
=='\r' || curChar
==' ')
2909 ME_SetSelection(editor
, car_pos
, car_pos
);
2910 RichEditANSIWndProc(editor
->hWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &default_format
);
2915 if (curf_ef
== def_ef
)
2918 prefx_cnt
= (sizeof(prefixes
)/sizeof(struct prefix_s
))-1;
2919 while (cur_prefx
<=prefx_cnt
)
2923 ft
.lpstrText
= prefixes
[cur_prefx
].text
;
2924 URLmin
=max(0,(car_pos
-prefixes
[cur_prefx
].length
));
2925 URLmax
=max(0, car_pos
);
2926 if ((car_pos
== 0) && (ME_GetTextLength(editor
) != 0))
2928 URLmax
= ME_GetTextLength(editor
)+1;
2930 ft
.chrg
.cpMin
= URLmin
;
2931 ft
.chrg
.cpMax
= URLmax
;
2932 text_pos
=RichEditANSIWndProc(editor
->hWnd
, EM_FINDTEXT
, FR_DOWN
, (LPARAM
)&ft
);
2938 url
.cpMax
=car_pos
-1;
2939 ME_SetCharFormat(editor
, text_pos
, (URLmax
-text_pos
), &link
);
2940 ME_RewrapRepaint(editor
);