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
232 #define STACK_SIZE_DEFAULT 100
233 #define STACK_SIZE_MAX 1000
235 #define TEXT_LIMIT_DEFAULT 32767
237 WINE_DEFAULT_DEBUG_CHANNEL(richedit
);
239 static BOOL
ME_RegisterEditorClass(HINSTANCE
);
241 static const WCHAR RichEdit20W
[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '2', '0', 'W', 0};
242 static const WCHAR RichEdit50W
[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '5', '0', 'W', 0};
243 static const WCHAR REListBox20W
[] = {'R','E','L','i','s','t','B','o','x','2','0','W', 0};
244 static const WCHAR REComboBox20W
[] = {'R','E','C','o','m','b','o','B','o','x','2','0','W', 0};
247 HANDLE me_heap
= NULL
;
249 static BOOL ME_ListBoxRegistered
= FALSE
;
250 static BOOL ME_ComboBoxRegistered
= FALSE
;
252 static inline int is_version_nt(void)
254 return !(GetVersion() & 0x80000000);
257 static ME_TextBuffer
*ME_MakeText(void) {
259 ME_TextBuffer
*buf
= ALLOC_OBJ(ME_TextBuffer
);
261 ME_DisplayItem
*p1
= ME_MakeDI(diTextStart
);
262 ME_DisplayItem
*p2
= ME_MakeDI(diTextEnd
);
268 p1
->member
.para
.next_para
= p2
;
269 p2
->member
.para
.prev_para
= p1
;
270 p2
->member
.para
.nCharOfs
= 0;
274 buf
->pCharStyle
= NULL
;
280 static LRESULT
ME_StreamInText(ME_TextEditor
*editor
, DWORD dwFormat
, ME_InStream
*stream
, ME_Style
*style
)
282 WCHAR wszText
[STREAMIN_BUFFER_SIZE
+1];
285 TRACE("%08x %p\n", dwFormat
, stream
);
292 ME_StreamInFill(stream
);
293 if (stream
->editstream
->dwError
)
299 if (!(dwFormat
& SF_UNICODE
))
301 /* FIXME? this is doomed to fail on true MBCS like UTF-8, luckily they're unlikely to be used as CP_ACP */
302 nWideChars
= MultiByteToWideChar(CP_ACP
, 0, stream
->buffer
, stream
->dwSize
, wszText
, STREAMIN_BUFFER_SIZE
);
307 nWideChars
= stream
->dwSize
>> 1;
308 pText
= (WCHAR
*)stream
->buffer
;
311 ME_InsertTextFromCursor(editor
, 0, pText
, nWideChars
, style
);
312 if (stream
->dwSize
== 0)
316 ME_CommitUndo(editor
);
317 ME_UpdateRepaint(editor
);
321 static void ME_RTFCharAttrHook(RTF_Info
*info
)
324 fmt
.cbSize
= sizeof(fmt
);
328 switch(info
->rtfMinor
)
331 /* FIXME add more flags once they're implemented */
332 fmt
.dwMask
= CFM_BOLD
| CFM_ITALIC
| CFM_UNDERLINE
| CFM_STRIKEOUT
| CFM_COLOR
| CFM_BACKCOLOR
| CFM_SIZE
| CFM_WEIGHT
;
333 fmt
.dwEffects
= CFE_AUTOCOLOR
| CFE_AUTOBACKCOLOR
;
334 fmt
.yHeight
= 12*20; /* 12pt */
338 fmt
.dwMask
= CFM_BOLD
;
339 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
342 fmt
.dwMask
= CFM_ITALIC
;
343 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
346 fmt
.dwMask
= CFM_UNDERLINE
;
347 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
348 fmt
.bUnderlineType
= CFU_CF1UNDERLINE
;
351 fmt
.dwMask
= CFM_UNDERLINE
;
355 fmt
.dwMask
= CFM_STRIKEOUT
;
356 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
360 case rtfSubScrShrink
:
361 case rtfSuperScrShrink
:
363 fmt
.dwMask
= CFM_SUBSCRIPT
|CFM_SUPERSCRIPT
;
364 if (info
->rtfMinor
== rtfSubScrShrink
) fmt
.dwEffects
= CFE_SUBSCRIPT
;
365 if (info
->rtfMinor
== rtfSuperScrShrink
) fmt
.dwEffects
= CFE_SUPERSCRIPT
;
366 if (info
->rtfMinor
== rtfNoSuperSub
) fmt
.dwEffects
= 0;
369 fmt
.dwMask
= CFM_HIDDEN
;
370 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
373 fmt
.dwMask
= CFM_BACKCOLOR
;
375 if (info
->rtfParam
== 0)
376 fmt
.dwEffects
= CFE_AUTOBACKCOLOR
;
377 else if (info
->rtfParam
!= rtfNoParam
)
379 RTFColor
*c
= RTFGetColor(info
, info
->rtfParam
);
380 fmt
.crTextColor
= (c
->rtfCBlue
<<16)|(c
->rtfCGreen
<<8)|(c
->rtfCRed
);
384 fmt
.dwMask
= CFM_COLOR
;
386 if (info
->rtfParam
== 0)
387 fmt
.dwEffects
= CFE_AUTOCOLOR
;
388 else if (info
->rtfParam
!= rtfNoParam
)
390 RTFColor
*c
= RTFGetColor(info
, info
->rtfParam
);
392 fmt
.crTextColor
= (c
->rtfCBlue
<<16)|(c
->rtfCGreen
<<8)|(c
->rtfCRed
);
398 if (info
->rtfParam
!= rtfNoParam
)
400 RTFFont
*f
= RTFGetFont(info
, info
->rtfParam
);
403 MultiByteToWideChar(CP_ACP
, 0, f
->rtfFName
, -1, fmt
.szFaceName
, sizeof(fmt
.szFaceName
)/sizeof(WCHAR
));
404 fmt
.szFaceName
[sizeof(fmt
.szFaceName
)/sizeof(WCHAR
)-1] = '\0';
405 fmt
.bCharSet
= f
->rtfFCharSet
;
406 fmt
.dwMask
= CFM_FACE
| CFM_CHARSET
;
411 fmt
.dwMask
= CFM_SIZE
;
412 if (info
->rtfParam
!= rtfNoParam
)
413 fmt
.yHeight
= info
->rtfParam
*10;
418 RTFFlushOutputBuffer(info
);
419 /* FIXME too slow ? how come ? */
420 style2
= ME_ApplyStyle(info
->style
, &fmt
);
421 ME_ReleaseStyle(info
->style
);
422 info
->style
= style2
;
423 info
->styleChanged
= TRUE
;
427 /* FIXME this function doesn't get any information about context of the RTF tag, which is very bad,
428 the same tags mean different things in different contexts */
429 static void ME_RTFParAttrHook(RTF_Info
*info
)
432 fmt
.cbSize
= sizeof(fmt
);
435 switch(info
->rtfMinor
)
437 case rtfParDef
: /* restores default paragraph attributes */
438 fmt
.dwMask
= PFM_ALIGNMENT
| PFM_TABSTOPS
| PFM_OFFSET
| PFM_STARTINDENT
;
439 fmt
.wAlignment
= PFA_LEFT
;
441 fmt
.dxOffset
= fmt
.dxStartIndent
= 0;
442 RTFFlushOutputBuffer(info
);
443 ME_GetParagraph(info
->editor
->pCursors
[0].pRun
)->member
.para
.bTable
= FALSE
;
447 ME_DisplayItem
*para
;
449 RTFFlushOutputBuffer(info
);
450 para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
451 assert(para
->member
.para
.pCells
);
452 para
->member
.para
.bTable
= TRUE
;
456 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
457 fmt
.dwMask
= PFM_STARTINDENT
| PFM_OFFSET
;
458 fmt
.dxStartIndent
+= info
->rtfParam
+ fmt
.dxOffset
;
459 fmt
.dxOffset
= -info
->rtfParam
;
462 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
463 fmt
.dwMask
= PFM_STARTINDENT
;
464 fmt
.dxStartIndent
= -fmt
.dxOffset
+ info
->rtfParam
;
467 fmt
.dwMask
= PFM_RIGHTINDENT
;
468 fmt
.dxRightIndent
= info
->rtfParam
;
472 fmt
.dwMask
= PFM_ALIGNMENT
;
473 fmt
.wAlignment
= PFA_LEFT
;
476 fmt
.dwMask
= PFM_ALIGNMENT
;
477 fmt
.wAlignment
= PFA_RIGHT
;
480 fmt
.dwMask
= PFM_ALIGNMENT
;
481 fmt
.wAlignment
= PFA_CENTER
;
484 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
485 if (!(fmt
.dwMask
& PFM_TABSTOPS
))
487 fmt
.dwMask
|= PFM_TABSTOPS
;
490 if (fmt
.cTabCount
< MAX_TAB_STOPS
)
491 fmt
.rgxTabs
[fmt
.cTabCount
++] = info
->rtfParam
;
495 RTFFlushOutputBuffer(info
);
496 /* FIXME too slow ? how come ?*/
497 ME_SetSelectionParaFormat(info
->editor
, &fmt
);
501 static void ME_RTFTblAttrHook(RTF_Info
*info
)
503 ME_DisplayItem
*para
;
505 switch (info
->rtfMinor
)
508 RTFFlushOutputBuffer(info
);
509 para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
511 /* Release possibly inherited cell definitions */
512 ME_DestroyTableCellList(para
);
514 para
->member
.para
.pCells
= ALLOC_OBJ(ME_TableCell
);
515 para
->member
.para
.pCells
->nRightBoundary
= 0;
516 para
->member
.para
.pCells
->next
= NULL
;
517 para
->member
.para
.pLastCell
= para
->member
.para
.pCells
;
520 RTFFlushOutputBuffer(info
);
521 para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
523 if (para
->member
.para
.pLastCell
->nRightBoundary
)
525 ME_TableCell
*pCell
= ALLOC_OBJ(ME_TableCell
);
528 para
->member
.para
.pLastCell
->next
= pCell
;
529 para
->member
.para
.pLastCell
= pCell
;
531 para
->member
.para
.pLastCell
->nRightBoundary
= info
->rtfParam
;
536 static void ME_RTFReadHook(RTF_Info
*info
) {
537 switch(info
->rtfClass
)
540 switch(info
->rtfMajor
)
543 if (info
->stackTop
< maxStack
) {
544 memcpy(&info
->stack
[info
->stackTop
].fmt
, &info
->style
->fmt
, sizeof(CHARFORMAT2W
));
545 info
->stack
[info
->stackTop
].codePage
= info
->codePage
;
546 info
->stack
[info
->stackTop
].unicodeLength
= info
->unicodeLength
;
549 info
->styleChanged
= FALSE
;
554 RTFFlushOutputBuffer(info
);
555 if (info
->stackTop
<=1) {
556 info
->rtfClass
= rtfEOF
;
560 assert(info
->stackTop
>= 0);
561 if (info
->styleChanged
)
563 /* FIXME too slow ? how come ? */
564 s
= ME_ApplyStyle(info
->style
, &info
->stack
[info
->stackTop
].fmt
);
565 ME_ReleaseStyle(info
->style
);
567 info
->codePage
= info
->stack
[info
->stackTop
].codePage
;
568 info
->unicodeLength
= info
->stack
[info
->stackTop
].unicodeLength
;
575 switch(info
->rtfMajor
)
578 ME_RTFCharAttrHook(info
);
581 ME_RTFParAttrHook(info
);
584 ME_RTFTblAttrHook(info
);
587 if (info
->rtfMinor
== rtfCell
)
589 RTFFlushOutputBuffer(info
);
590 ME_InsertTableCellFromCursor(info
->editor
, 0);
598 ME_StreamInFill(ME_InStream
*stream
)
600 stream
->editstream
->dwError
= stream
->editstream
->pfnCallback(stream
->editstream
->dwCookie
,
601 (BYTE
*)stream
->buffer
,
602 sizeof(stream
->buffer
),
603 (LONG
*)&stream
->dwSize
);
607 static LRESULT
ME_StreamIn(ME_TextEditor
*editor
, DWORD format
, EDITSTREAM
*stream
)
611 int from
, to
, to2
, nUndoMode
;
612 int nEventMask
= editor
->nEventMask
;
613 ME_InStream inStream
;
615 TRACE("stream==%p hWnd==%p format==0x%X\n", stream
, editor
->hWnd
, (UINT
)format
);
616 editor
->nEventMask
= 0;
618 ME_GetSelection(editor
, &from
, &to
);
619 if ((format
& SFF_SELECTION
) && (editor
->mode
& TM_RICHTEXT
)) {
620 style
= ME_GetSelectionInsertStyle(editor
);
622 ME_InternalDeleteText(editor
, from
, to
-from
);
625 style
= editor
->pBuffer
->pDefaultStyle
;
626 ME_AddRefStyle(style
);
627 SendMessageA(editor
->hWnd
, EM_SETSEL
, 0, 0);
628 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
));
630 ME_ClearTempStyle(editor
);
631 /* FIXME restore default paragraph formatting ! */
635 /* Back up undo mode to a local variable */
636 nUndoMode
= editor
->nUndoMode
;
638 /* Only create an undo if SFF_SELECTION is set */
639 if (!(format
& SFF_SELECTION
))
640 editor
->nUndoMode
= umIgnore
;
642 inStream
.editstream
= stream
;
643 inStream
.editstream
->dwError
= 0;
649 /* Check if it's really RTF, and if it is not, use plain text */
650 ME_StreamInFill(&inStream
);
651 if (!inStream
.editstream
->dwError
)
653 if (strncmp(inStream
.buffer
, "{\\rtf", 5) && strncmp(inStream
.buffer
, "{\\urtf", 6))
661 if (!inStream
.editstream
->dwError
)
663 if (format
& SF_RTF
) {
664 /* setup the RTF parser */
665 memset(&parser
, 0, sizeof parser
);
666 RTFSetEditStream(&parser
, &inStream
);
667 parser
.rtfFormat
= format
&(SF_TEXT
|SF_RTF
);
668 parser
.hwndEdit
= editor
->hWnd
;
669 parser
.editor
= editor
;
670 parser
.style
= style
;
673 RTFSetReadHook(&parser
, ME_RTFReadHook
);
678 RTFFlushOutputBuffer(&parser
);
681 style
= parser
.style
;
683 else if (format
& SF_TEXT
)
684 ME_StreamInText(editor
, format
, &inStream
, style
);
686 ERR("EM_STREAMIN without SF_TEXT or SF_RTF\n");
687 ME_GetSelection(editor
, &to
, &to2
);
688 /* put the cursor at the top */
689 if (!(format
& SFF_SELECTION
))
690 SendMessageA(editor
->hWnd
, EM_SETSEL
, 0, 0);
693 /* Restore saved undo mode */
694 editor
->nUndoMode
= nUndoMode
;
696 /* even if we didn't add an undo, we need to commit anything on the stack */
697 ME_CommitUndo(editor
);
699 /* If SFF_SELECTION isn't set, delete any undos from before we started too */
700 if (!(format
& SFF_SELECTION
))
701 ME_EmptyUndoStack(editor
);
703 ME_ReleaseStyle(style
);
704 editor
->nEventMask
= nEventMask
;
707 ME_UpdateRepaint(editor
);
709 if (!(format
& SFF_SELECTION
)) {
710 ME_ClearTempStyle(editor
);
712 ME_MoveCaret(editor
);
713 ME_SendSelChange(editor
);
714 ME_SendRequestResize(editor
, FALSE
);
720 typedef struct tagME_RTFStringStreamStruct
725 } ME_RTFStringStreamStruct
;
727 static DWORD CALLBACK
ME_ReadFromRTFString(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
729 ME_RTFStringStreamStruct
*pStruct
= (ME_RTFStringStreamStruct
*)dwCookie
;
732 count
= min(cb
, pStruct
->length
- pStruct
->pos
);
733 memmove(lpBuff
, pStruct
->string
+ pStruct
->pos
, count
);
734 pStruct
->pos
+= count
;
740 ME_StreamInRTFString(ME_TextEditor
*editor
, BOOL selection
, char *string
)
743 ME_RTFStringStreamStruct data
;
745 data
.string
= string
;
746 data
.length
= strlen(string
);
748 es
.dwCookie
= (DWORD
)&data
;
749 es
.pfnCallback
= ME_ReadFromRTFString
;
750 ME_StreamIn(editor
, SF_RTF
| (selection
? SFF_SELECTION
: 0), &es
);
755 ME_FindItemAtOffset(ME_TextEditor
*editor
, ME_DIType nItemType
, int nOffset
, int *nItemOffset
)
757 ME_DisplayItem
*item
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
759 while (item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= nOffset
)
760 item
= ME_FindItemFwd(item
, diParagraph
);
765 nOffset
-= item
->member
.para
.nCharOfs
;
766 if (nItemType
== diParagraph
) {
768 *nItemOffset
= nOffset
;
773 item
= ME_FindItemFwd(item
, diRun
);
774 } while (item
&& (item
->member
.run
.nCharOfs
+ ME_StrLen(item
->member
.run
.strText
) <= nOffset
));
776 nOffset
-= item
->member
.run
.nCharOfs
;
778 *nItemOffset
= nOffset
;
785 ME_FindText(ME_TextEditor
*editor
, DWORD flags
, const CHARRANGE
*chrg
, const WCHAR
*text
, CHARRANGE
*chrgText
)
787 const int nLen
= lstrlenW(text
);
788 const int nTextLen
= ME_GetTextLength(editor
);
791 ME_DisplayItem
*item
;
792 ME_DisplayItem
*para
;
793 WCHAR wLastChar
= ' ';
795 TRACE("flags==0x%08x, chrg->cpMin==%d, chrg->cpMax==%d text==%s\n",
796 flags
, chrg
->cpMin
, chrg
->cpMax
, debugstr_w(text
));
798 if (flags
& ~(FR_DOWN
| FR_MATCHCASE
| FR_WHOLEWORD
))
799 FIXME("Flags 0x%08x not implemented\n",
800 flags
& ~(FR_DOWN
| FR_MATCHCASE
| FR_WHOLEWORD
));
803 if (chrg
->cpMax
== -1)
806 nMax
= chrg
->cpMax
> nTextLen
? nTextLen
: chrg
->cpMax
;
808 /* when searching up, if cpMin < cpMax, then instead of searching
809 * on [cpMin,cpMax], we search on [0,cpMin], otherwise, search on
810 * [cpMax, cpMin]. The exception is when cpMax is -1, in which
811 * case, it is always bigger than cpMin.
813 if (!(flags
& FR_DOWN
))
817 nMax
= nMin
> nTextLen
? nTextLen
: nMin
;
818 if (nMin
< nSwap
|| chrg
->cpMax
== -1)
824 if (!nLen
|| nMin
< 0 || nMax
< 0 || nMax
< nMin
)
827 chrgText
->cpMin
= chrgText
->cpMax
= -1;
831 if (flags
& FR_DOWN
) /* Forward search */
833 /* If possible, find the character before where the search starts */
834 if ((flags
& FR_WHOLEWORD
) && nMin
)
837 item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
841 chrgText
->cpMin
= chrgText
->cpMax
= -1;
844 wLastChar
= item
->member
.run
.strText
->szData
[nStart
];
848 item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
852 chrgText
->cpMin
= chrgText
->cpMax
= -1;
856 para
= ME_GetParagraph(item
);
858 && para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
+ nLen
<= nMax
)
860 ME_DisplayItem
*pCurItem
= item
;
861 int nCurStart
= nStart
;
864 while (pCurItem
&& ME_CharCompare(pCurItem
->member
.run
.strText
->szData
[nCurStart
+ nMatched
], text
[nMatched
], (flags
& FR_MATCHCASE
)))
866 if ((flags
& FR_WHOLEWORD
) && isalnumW(wLastChar
))
870 if (nMatched
== nLen
)
872 ME_DisplayItem
*pNextItem
= pCurItem
;
873 int nNextStart
= nCurStart
;
876 /* Check to see if next character is a whitespace */
877 if (flags
& FR_WHOLEWORD
)
879 if (nCurStart
+ nMatched
== ME_StrLen(pCurItem
->member
.run
.strText
))
881 pNextItem
= ME_FindItemFwd(pCurItem
, diRun
);
882 nNextStart
= -nMatched
;
886 wNextChar
= pNextItem
->member
.run
.strText
->szData
[nNextStart
+ nMatched
];
890 if (isalnumW(wNextChar
))
894 nStart
+= para
->member
.para
.nCharOfs
+ pCurItem
->member
.run
.nCharOfs
;
897 chrgText
->cpMin
= nStart
;
898 chrgText
->cpMax
= nStart
+ nLen
;
900 TRACE("found at %d-%d\n", nStart
, nStart
+ nLen
);
903 if (nCurStart
+ nMatched
== ME_StrLen(pCurItem
->member
.run
.strText
))
905 pCurItem
= ME_FindItemFwd(pCurItem
, diRun
);
906 para
= ME_GetParagraph(pCurItem
);
907 nCurStart
= -nMatched
;
911 wLastChar
= pCurItem
->member
.run
.strText
->szData
[nCurStart
+ nMatched
];
916 if (nStart
== ME_StrLen(item
->member
.run
.strText
))
918 item
= ME_FindItemFwd(item
, diRun
);
919 para
= ME_GetParagraph(item
);
924 else /* Backward search */
926 /* If possible, find the character after where the search ends */
927 if ((flags
& FR_WHOLEWORD
) && nMax
< nTextLen
- 1)
930 item
= ME_FindItemAtOffset(editor
, diRun
, nEnd
, &nEnd
);
934 chrgText
->cpMin
= chrgText
->cpMax
= -1;
937 wLastChar
= item
->member
.run
.strText
->szData
[nEnd
];
941 item
= ME_FindItemAtOffset(editor
, diRun
, nEnd
, &nEnd
);
945 chrgText
->cpMin
= chrgText
->cpMax
= -1;
949 para
= ME_GetParagraph(item
);
952 && para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nEnd
- nLen
>= nMin
)
954 ME_DisplayItem
*pCurItem
= item
;
958 if (nCurEnd
- nMatched
== 0)
960 pCurItem
= ME_FindItemBack(pCurItem
, diRun
);
961 para
= ME_GetParagraph(pCurItem
);
962 nCurEnd
= ME_StrLen(pCurItem
->member
.run
.strText
) + nMatched
;
965 while (pCurItem
&& ME_CharCompare(pCurItem
->member
.run
.strText
->szData
[nCurEnd
- nMatched
- 1], text
[nLen
- nMatched
- 1], (flags
& FR_MATCHCASE
)))
967 if ((flags
& FR_WHOLEWORD
) && isalnumW(wLastChar
))
971 if (nMatched
== nLen
)
973 ME_DisplayItem
*pPrevItem
= pCurItem
;
974 int nPrevEnd
= nCurEnd
;
977 /* Check to see if previous character is a whitespace */
978 if (flags
& FR_WHOLEWORD
)
980 if (nPrevEnd
- nMatched
== 0)
982 pPrevItem
= ME_FindItemBack(pCurItem
, diRun
);
984 nPrevEnd
= ME_StrLen(pPrevItem
->member
.run
.strText
) + nMatched
;
988 wPrevChar
= pPrevItem
->member
.run
.strText
->szData
[nPrevEnd
- nMatched
- 1];
992 if (isalnumW(wPrevChar
))
996 nStart
= para
->member
.para
.nCharOfs
+ pCurItem
->member
.run
.nCharOfs
+ nCurEnd
- nMatched
;
999 chrgText
->cpMin
= nStart
;
1000 chrgText
->cpMax
= nStart
+ nLen
;
1002 TRACE("found at %d-%d\n", nStart
, nStart
+ nLen
);
1005 if (nCurEnd
- nMatched
== 0)
1007 pCurItem
= ME_FindItemBack(pCurItem
, diRun
);
1008 /* Don't care about pCurItem becoming NULL here; it's already taken
1009 * care of in the exterior loop condition */
1010 para
= ME_GetParagraph(pCurItem
);
1011 nCurEnd
= ME_StrLen(pCurItem
->member
.run
.strText
) + nMatched
;
1015 wLastChar
= pCurItem
->member
.run
.strText
->szData
[nCurEnd
- nMatched
- 1];
1022 item
= ME_FindItemBack(item
, diRun
);
1023 para
= ME_GetParagraph(item
);
1024 nEnd
= ME_StrLen(item
->member
.run
.strText
);
1028 TRACE("not found\n");
1030 chrgText
->cpMin
= chrgText
->cpMax
= -1;
1036 ME_KeyDown(ME_TextEditor
*editor
, WORD nKey
)
1038 BOOL ctrl_is_down
= GetKeyState(VK_CONTROL
) & 0x8000;
1039 BOOL shift_is_down
= GetKeyState(VK_SHIFT
) & 0x8000;
1051 ME_ArrowKey(editor
, nKey
, shift_is_down
, ctrl_is_down
);
1055 /* FIXME backspace and delete aren't the same, they act different wrt paragraph style of the merged paragraph */
1056 if (GetWindowLongW(editor
->hWnd
, GWL_STYLE
) & ES_READONLY
)
1058 if (ME_IsSelection(editor
))
1059 ME_DeleteSelection(editor
);
1060 else if (nKey
== VK_DELETE
|| ME_ArrowKey(editor
, VK_LEFT
, FALSE
, FALSE
))
1061 ME_DeleteTextAtCursor(editor
, 1, 1);
1064 ME_CommitUndo(editor
);
1065 ME_UpdateRepaint(editor
);
1066 ME_SendRequestResize(editor
, FALSE
);
1076 chf
.cbSize
= sizeof(chf
);
1078 ME_GetSelectionCharFormat(editor
, &chf
);
1079 ME_DumpStyleToBuf(&chf
, buf
);
1080 MessageBoxA(NULL
, buf
, "Style dump", MB_OK
);
1084 ME_CheckCharOffsets(editor
);
1091 static BOOL
ME_ShowContextMenu(ME_TextEditor
*editor
, int x
, int y
)
1096 if(!editor
->lpOleCallback
)
1098 ME_GetSelection(editor
, (int *)&selrange
.cpMin
, (int *)&selrange
.cpMax
);
1099 if(selrange
.cpMin
== selrange
.cpMax
)
1100 seltype
|= SEL_EMPTY
;
1103 /* FIXME: Handle objects */
1104 seltype
|= SEL_TEXT
;
1105 if(selrange
.cpMax
-selrange
.cpMin
> 1)
1106 seltype
|= SEL_MULTICHAR
;
1108 if(SUCCEEDED(IRichEditOleCallback_GetContextMenu(editor
->lpOleCallback
, seltype
, NULL
, &selrange
, &menu
)))
1110 TrackPopupMenu(menu
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, GetParent(editor
->hWnd
), NULL
);
1116 ME_TextEditor
*ME_MakeEditor(HWND hWnd
) {
1117 ME_TextEditor
*ed
= ALLOC_OBJ(ME_TextEditor
);
1121 ed
->bEmulateVersion10
= FALSE
;
1122 ed
->pBuffer
= ME_MakeText();
1124 ME_MakeFirstParagraph(hDC
, ed
->pBuffer
);
1125 ReleaseDC(hWnd
, hDC
);
1126 ed
->bCaretShown
= FALSE
;
1128 ed
->pCursors
= ALLOC_N_OBJ(ME_Cursor
, ed
->nCursors
);
1129 ed
->pCursors
[0].pRun
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diRun
);
1130 ed
->pCursors
[0].nOffset
= 0;
1131 ed
->pCursors
[1].pRun
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diRun
);
1132 ed
->pCursors
[1].nOffset
= 0;
1133 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 ed
->bHaveFocus
= FALSE
;
1159 GetClientRect(hWnd
, &ed
->rcFormat
);
1160 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
1162 ed
->pFontCache
[i
].nRefs
= 0;
1163 ed
->pFontCache
[i
].nAge
= 0;
1164 ed
->pFontCache
[i
].hFont
= NULL
;
1167 ME_CheckCharOffsets(ed
);
1169 if (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_PASSWORD
)
1170 ed
->cPasswordMask
= '*';
1172 ed
->cPasswordMask
= 0;
1177 typedef struct tagME_GlobalDestStruct
1181 } ME_GlobalDestStruct
;
1183 static DWORD CALLBACK
ME_ReadFromHGLOBALUnicode(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
1185 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
1190 pDest
= (WORD
*)lpBuff
;
1191 pSrc
= (WORD
*)GlobalLock(pData
->hData
);
1192 for (i
= 0; i
<cb
&& pSrc
[pData
->nLength
+i
]; i
++) {
1193 pDest
[i
] = pSrc
[pData
->nLength
+i
];
1195 pData
->nLength
+= i
;
1197 GlobalUnlock(pData
->hData
);
1201 static DWORD CALLBACK
ME_ReadFromHGLOBALRTF(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
1203 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
1208 pSrc
= (BYTE
*)GlobalLock(pData
->hData
);
1209 for (i
= 0; i
<cb
&& pSrc
[pData
->nLength
+i
]; i
++) {
1210 pDest
[i
] = pSrc
[pData
->nLength
+i
];
1212 pData
->nLength
+= i
;
1214 GlobalUnlock(pData
->hData
);
1219 void ME_DestroyEditor(ME_TextEditor
*editor
)
1221 ME_DisplayItem
*pFirst
= editor
->pBuffer
->pFirst
;
1222 ME_DisplayItem
*p
= pFirst
, *pNext
= NULL
;
1225 ME_ClearTempStyle(editor
);
1226 ME_EmptyUndoStack(editor
);
1229 ME_DestroyDisplayItem(p
);
1232 ME_ReleaseStyle(editor
->pBuffer
->pDefaultStyle
);
1233 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
1235 if (editor
->pFontCache
[i
].hFont
)
1236 DeleteObject(editor
->pFontCache
[i
].hFont
);
1238 DeleteObject(editor
->hbrBackground
);
1239 if(editor
->lpOleCallback
)
1240 IUnknown_Release(editor
->lpOleCallback
);
1242 FREE_OBJ(editor
->pBuffer
);
1243 FREE_OBJ(editor
->pCursors
);
1248 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
1253 case DLL_PROCESS_ATTACH
:
1254 DisableThreadLibraryCalls(hinstDLL
);
1255 me_heap
= HeapCreate (0, 0x10000, 0);
1256 if (!ME_RegisterEditorClass(hinstDLL
)) return FALSE
;
1260 case DLL_PROCESS_DETACH
:
1261 UnregisterClassW(RichEdit20W
, 0);
1262 UnregisterClassW(RichEdit50W
, 0);
1263 UnregisterClassA("RichEdit20A", 0);
1264 UnregisterClassA("RichEdit50A", 0);
1265 if (ME_ListBoxRegistered
)
1266 UnregisterClassW(REListBox20W
, 0);
1267 if (ME_ComboBoxRegistered
)
1268 UnregisterClassW(REComboBox20W
, 0);
1270 HeapDestroy (me_heap
);
1278 #define UNSUPPORTED_MSG(e) \
1280 FIXME(#e ": stub\n"); \
1281 return DefWindowProcW(hWnd, msg, wParam, lParam);
1283 static const char * const edit_messages
[] = {
1312 "EM_SETPASSWORDCHAR",
1313 "EM_EMPTYUNDOBUFFER",
1314 "EM_GETFIRSTVISIBLELINE",
1316 "EM_SETWORDBREAKPROC",
1317 "EM_GETWORDBREAKPROC",
1318 "EM_GETPASSWORDCHAR",
1326 static const char * const richedit_messages
[] = {
1331 "EM_EXLINEFROMCHAR",
1337 "EM_GETOLEINTERFACE",
1347 "EM_SETOLECALLBACK",
1349 "EM_SETTARGETDEVICE",
1357 "EM_GETWORDBREAKPROCEX",
1358 "EM_SETWORDBREAKPROCEX",
1360 "EM_UNKNOWN_USER_83",
1365 "EM_STOPGROUPTYPING",
1369 "EM_GETAUTOURLDETECT",
1372 "EM_GETTEXTLENGTHEX",
1375 "EM_UNKNOWN_USER_98",
1376 "EM_UNKNOWN_USER_99",
1377 "EM_SETPUNCTUATION",
1378 "EM_GETPUNCTUATION",
1379 "EM_SETWORDWRAPMODE",
1380 "EM_GETWORDWRAPMODE",
1386 "EM_UNKNOWN_USER_109",
1387 "EM_UNKNOWN_USER_110",
1388 "EM_UNKNOWN_USER_111",
1389 "EM_UNKNOWN_USER_112",
1390 "EM_UNKNOWN_USER_113",
1391 "EM_UNKNOWN_USER_114",
1392 "EM_UNKNOWN_USER_115",
1393 "EM_UNKNOWN_USER_116",
1394 "EM_UNKNOWN_USER_117",
1395 "EM_UNKNOWN_USER_118",
1396 "EM_UNKNOWN_USER_119",
1397 "EM_SETLANGOPTIONS",
1398 "EM_GETLANGOPTIONS",
1399 "EM_GETIMECOMPMODE",
1403 "EM_SETIMEMODEBIAS",
1408 get_msg_name(UINT msg
)
1410 if (msg
>= EM_GETSEL
&& msg
<= EM_CHARFROMPOS
)
1411 return edit_messages
[msg
- EM_GETSEL
];
1412 if (msg
>= EM_CANPASTE
&& msg
<= EM_GETIMEMODEBIAS
)
1413 return richedit_messages
[msg
- EM_CANPASTE
];
1417 static LRESULT
RichEditWndProc_common(HWND hWnd
, UINT msg
, WPARAM wParam
,
1418 LPARAM lParam
, BOOL unicode
)
1420 ME_TextEditor
*editor
= (ME_TextEditor
*)GetWindowLongPtrW(hWnd
, 0);
1422 TRACE("hwnd %p msg %04x (%s) %lx %lx, unicode %d\n",
1423 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
, unicode
);
1425 if (!editor
&& msg
!= WM_NCCREATE
&& msg
!= WM_NCDESTROY
) {
1426 ERR("called with invalid hWnd %p - application bug?\n", hWnd
);
1432 UNSUPPORTED_MSG(EM_DISPLAYBAND
)
1433 UNSUPPORTED_MSG(EM_FINDWORDBREAK
)
1434 UNSUPPORTED_MSG(EM_FMTLINES
)
1435 UNSUPPORTED_MSG(EM_FORMATRANGE
)
1436 UNSUPPORTED_MSG(EM_GETBIDIOPTIONS
)
1437 UNSUPPORTED_MSG(EM_GETEDITSTYLE
)
1438 UNSUPPORTED_MSG(EM_GETIMECOMPMODE
)
1439 /* UNSUPPORTED_MSG(EM_GETIMESTATUS) missing in Wine headers */
1440 UNSUPPORTED_MSG(EM_GETLANGOPTIONS
)
1441 /* UNSUPPORTED_MSG(EM_GETOLEINTERFACE) separate stub */
1442 UNSUPPORTED_MSG(EM_GETREDONAME
)
1443 UNSUPPORTED_MSG(EM_GETTEXTMODE
)
1444 UNSUPPORTED_MSG(EM_GETTYPOGRAPHYOPTIONS
)
1445 UNSUPPORTED_MSG(EM_GETUNDONAME
)
1446 UNSUPPORTED_MSG(EM_GETWORDBREAKPROCEX
)
1447 UNSUPPORTED_MSG(EM_PASTESPECIAL
)
1448 UNSUPPORTED_MSG(EM_SELECTIONTYPE
)
1449 UNSUPPORTED_MSG(EM_SETBIDIOPTIONS
)
1450 UNSUPPORTED_MSG(EM_SETEDITSTYLE
)
1451 UNSUPPORTED_MSG(EM_SETFONTSIZE
)
1452 UNSUPPORTED_MSG(EM_SETLANGOPTIONS
)
1453 UNSUPPORTED_MSG(EM_SETPALETTE
)
1454 UNSUPPORTED_MSG(EM_SETTABSTOPS
)
1455 UNSUPPORTED_MSG(EM_SETTARGETDEVICE
)
1456 UNSUPPORTED_MSG(EM_SETTYPOGRAPHYOPTIONS
)
1457 UNSUPPORTED_MSG(EM_SETWORDBREAKPROCEX
)
1458 UNSUPPORTED_MSG(WM_STYLECHANGING
)
1459 UNSUPPORTED_MSG(WM_STYLECHANGED
)
1460 /* UNSUPPORTED_MSG(WM_UNICHAR) FIXME missing in Wine headers */
1462 /* Messages specific to Richedit controls */
1465 return ME_StreamIn(editor
, wParam
, (EDITSTREAM
*)lParam
);
1467 return ME_StreamOut(editor
, wParam
, (EDITSTREAM
*)lParam
);
1470 UINT code
= DLGC_WANTCHARS
|DLGC_WANTARROWS
;
1471 if(lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
1473 int vk
= (int)((LPMSG
)lParam
)->wParam
;
1474 /* if style says we want return key */
1475 if((vk
== VK_RETURN
) && (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_WANTRETURN
))
1477 code
|= DLGC_WANTMESSAGE
;
1479 /* we always handle ctrl-tab */
1480 if((vk
== VK_TAB
) && (GetKeyState(VK_CONTROL
) & 0x8000))
1482 code
|= DLGC_WANTMESSAGE
;
1489 CREATESTRUCTW
*pcs
= (CREATESTRUCTW
*)lParam
;
1490 TRACE("WM_NCCREATE: style 0x%08x\n", pcs
->style
);
1491 editor
= ME_MakeEditor(hWnd
);
1492 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)editor
);
1495 case EM_EMPTYUNDOBUFFER
:
1496 ME_EmptyUndoStack(editor
);
1500 /* Note: wParam/lParam can be NULL */
1502 PUINT pfrom
= wParam
? (PUINT
)wParam
: &from
;
1503 PUINT pto
= lParam
? (PUINT
)lParam
: &to
;
1504 ME_GetSelection(editor
, (int *)pfrom
, (int *)pto
);
1505 if ((*pfrom
|*pto
) & 0xFFFF0000)
1507 return MAKELONG(*pfrom
,*pto
);
1511 CHARRANGE
*pRange
= (CHARRANGE
*)lParam
;
1512 ME_GetSelection(editor
, (int *)&pRange
->cpMin
, (int *)&pRange
->cpMax
);
1513 TRACE("EM_EXGETSEL = (%d,%d)\n", pRange
->cpMin
, pRange
->cpMax
);
1516 case EM_SETUNDOLIMIT
:
1518 if ((int)wParam
< 0)
1519 editor
->nUndoLimit
= STACK_SIZE_DEFAULT
;
1521 editor
->nUndoLimit
= min(wParam
, STACK_SIZE_MAX
);
1522 /* Setting a max stack size keeps wine from getting killed
1523 for hogging memory. Windows allocates all this memory at once, so
1524 no program would realistically set a value above our maximum. */
1525 return editor
->nUndoLimit
;
1528 return editor
->pUndoStack
!= NULL
;
1530 return editor
->pRedoStack
!= NULL
;
1531 case WM_UNDO
: /* FIXME: actually not the same */
1540 /* these flags are equivalent to the ES_* counterparts */
1541 DWORD mask
= ECO_VERTICAL
| ECO_AUTOHSCROLL
| ECO_AUTOVSCROLL
|
1542 ECO_NOHIDESEL
| ECO_READONLY
| ECO_WANTRETURN
;
1543 DWORD settings
= GetWindowLongW(hWnd
, GWL_STYLE
) & mask
;
1549 /* these flags are equivalent to ES_* counterparts
1550 * ECO_READONLY is already implemented in the code, only requires
1551 * setting the bit to work
1553 DWORD mask
= ECO_VERTICAL
| ECO_AUTOHSCROLL
| ECO_AUTOVSCROLL
|
1554 ECO_NOHIDESEL
| ECO_READONLY
| ECO_WANTRETURN
;
1555 DWORD raw
= GetWindowLongW(hWnd
, GWL_STYLE
);
1556 DWORD settings
= mask
& raw
;
1572 SetWindowLongW(hWnd
, GWL_STYLE
, (raw
& ~mask
) | (settings
& mask
));
1574 if (lParam
& ECO_AUTOWORDSELECTION
)
1575 FIXME("ECO_AUTOWORDSELECTION not implemented yet!\n");
1576 if (lParam
& ECO_SELECTIONBAR
)
1577 FIXME("ECO_SELECTIONBAR not implemented yet!\n");
1578 if (lParam
& ECO_VERTICAL
)
1579 FIXME("ECO_VERTICAL not implemented yet!\n");
1580 if (lParam
& ECO_AUTOHSCROLL
)
1581 FIXME("ECO_AUTOHSCROLL not implemented yet!\n");
1582 if (lParam
& ECO_AUTOVSCROLL
)
1583 FIXME("ECO_AUTOVSCROLL not implemented yet!\n");
1584 if (lParam
& ECO_NOHIDESEL
)
1585 FIXME("ECO_NOHIDESEL not implemented yet!\n");
1586 if (lParam
& ECO_WANTRETURN
)
1587 FIXME("ECO_WANTRETURN not implemented yet!\n");
1593 ME_InvalidateSelection(editor
);
1594 ME_SetSelection(editor
, wParam
, lParam
);
1595 ME_InvalidateSelection(editor
);
1596 ME_SendSelChange(editor
);
1599 case EM_SETSCROLLPOS
:
1601 POINT
*point
= (POINT
*)lParam
;
1602 ME_ScrollAbs(editor
, point
->y
);
1605 case EM_AUTOURLDETECT
:
1607 if (wParam
==1 || wParam
==0)
1609 editor
->AutoURLDetect_bEnable
= (BOOL
)wParam
;
1612 return E_INVALIDARG
;
1614 case EM_GETAUTOURLDETECT
:
1616 return editor
->AutoURLDetect_bEnable
;
1621 CHARRANGE range
= *(CHARRANGE
*)lParam
;
1623 TRACE("EM_EXSETSEL (%d,%d)\n", range
.cpMin
, range
.cpMax
);
1625 ME_InvalidateSelection(editor
);
1626 end
= ME_SetSelection(editor
, range
.cpMin
, range
.cpMax
);
1627 ME_InvalidateSelection(editor
);
1628 ME_SendSelChange(editor
);
1632 case EM_SHOWSCROLLBAR
:
1634 ShowScrollBar(editor
->hWnd
, wParam
, lParam
);
1640 SETTEXTEX
*pStruct
= (SETTEXTEX
*)wParam
;
1644 int oldModify
= editor
->nModifyStep
;
1646 if (!pStruct
) return 0;
1648 TRACE("EM_SETTEXTEX - %s, flags %d, cp %d\n",
1649 pStruct
->codepage
== 1200 ? debugstr_w((LPCWSTR
)lParam
) : debugstr_a((LPCSTR
)lParam
),
1650 pStruct
->flags
, pStruct
->codepage
);
1652 /* FIXME: make use of pStruct->codepage in the to unicode translation */
1653 wszText
= lParam
? ME_ToUnicode(pStruct
->codepage
== 1200, (void *)lParam
) : NULL
;
1654 len
= wszText
? lstrlenW(wszText
) : 0;
1656 /* FIXME: this should support RTF strings too, according to MSDN */
1657 if (pStruct
->flags
& ST_SELECTION
) {
1658 ME_GetSelection(editor
, &from
, &to
);
1659 style
= ME_GetSelectionInsertStyle(editor
);
1660 ME_InternalDeleteText(editor
, from
, to
- from
);
1661 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, style
);
1662 ME_ReleaseStyle(style
);
1665 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
));
1666 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, editor
->pBuffer
->pDefaultStyle
);
1669 ME_CommitUndo(editor
);
1670 if (!(pStruct
->flags
& ST_KEEPUNDO
))
1672 editor
->nModifyStep
= oldModify
;
1673 ME_EmptyUndoStack(editor
);
1675 ME_UpdateRepaint(editor
);
1678 case EM_SETBKGNDCOLOR
:
1680 LRESULT lColor
= ME_GetBackColor(editor
);
1681 if (editor
->rgbBackColor
!= -1)
1682 DeleteObject(editor
->hbrBackground
);
1685 editor
->rgbBackColor
= -1;
1686 editor
->hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
1690 editor
->rgbBackColor
= lParam
;
1691 editor
->hbrBackground
= CreateSolidBrush(editor
->rgbBackColor
);
1693 if (editor
->bRedraw
)
1695 InvalidateRect(hWnd
, NULL
, TRUE
);
1701 return editor
->nModifyStep
== 0 ? 0 : 1;
1705 editor
->nModifyStep
= 1;
1707 editor
->nModifyStep
= 0;
1711 case EM_SETREADONLY
:
1713 long nStyle
= GetWindowLongW(hWnd
, GWL_STYLE
);
1715 nStyle
|= ES_READONLY
;
1717 nStyle
&= ~ES_READONLY
;
1718 SetWindowLongW(hWnd
, GWL_STYLE
, nStyle
);
1721 case EM_SETEVENTMASK
:
1723 DWORD nOldMask
= editor
->nEventMask
;
1725 editor
->nEventMask
= lParam
;
1728 case EM_GETEVENTMASK
:
1729 return editor
->nEventMask
;
1730 case EM_SETCHARFORMAT
:
1732 CHARFORMAT2W buf
, *p
;
1733 BOOL bRepaint
= TRUE
;
1734 p
= ME_ToCF2W(&buf
, (CHARFORMAT2W
*)lParam
);
1735 if (!wParam
|| (editor
->mode
& TM_PLAINTEXT
))
1736 ME_SetDefaultCharFormat(editor
, p
);
1737 else if (wParam
== (SCF_WORD
| SCF_SELECTION
))
1738 FIXME("EM_SETCHARFORMAT: word selection not supported\n");
1739 else if (wParam
== SCF_ALL
)
1740 ME_SetCharFormat(editor
, 0, ME_GetTextLength(editor
), p
);
1743 ME_GetSelection(editor
, &from
, &to
);
1744 bRepaint
= (from
!= to
);
1745 ME_SetSelectionCharFormat(editor
, p
);
1747 editor
->nModifyStep
= 1;
1748 ME_CommitUndo(editor
);
1750 ME_RewrapRepaint(editor
);
1753 case EM_GETCHARFORMAT
:
1755 CHARFORMAT2W tmp
, *dst
= (CHARFORMAT2W
*)lParam
;
1756 if (dst
->cbSize
!= sizeof(CHARFORMATA
) &&
1757 dst
->cbSize
!= sizeof(CHARFORMATW
) &&
1758 dst
->cbSize
!= sizeof(CHARFORMAT2A
) &&
1759 dst
->cbSize
!= sizeof(CHARFORMAT2W
))
1761 tmp
.cbSize
= sizeof(tmp
);
1763 ME_GetDefaultCharFormat(editor
, &tmp
);
1765 ME_GetSelectionCharFormat(editor
, &tmp
);
1766 ME_CopyToCFAny(dst
, &tmp
);
1769 case EM_SETPARAFORMAT
:
1770 ME_SetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
1771 ME_RewrapRepaint(editor
);
1772 ME_CommitUndo(editor
);
1774 case EM_GETPARAFORMAT
:
1775 ME_GetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
1777 case EM_GETFIRSTVISIBLELINE
:
1779 ME_DisplayItem
*p
= editor
->pBuffer
->pFirst
;
1780 int y
= ME_GetYScrollPos(editor
);
1785 p
= ME_FindItemFwd(p
, diStartRowOrParagraphOrEnd
);
1786 if (p
->type
== diTextEnd
)
1788 if (p
->type
== diParagraph
) {
1789 ypara
= p
->member
.para
.nYPos
;
1792 ystart
= ypara
+ p
->member
.row
.nYPos
;
1793 yend
= ystart
+ p
->member
.row
.nHeight
;
1801 case EM_HIDESELECTION
:
1803 editor
->bHideSelection
= (wParam
!= 0);
1804 ME_InvalidateSelection(editor
);
1809 ME_ScrollDown(editor
, lParam
* 8); /* FIXME follow the original */
1810 return TRUE
; /* Should return false if a single line richedit control */
1815 ME_GetSelection(editor
, &from
, &to
);
1816 ME_InternalDeleteText(editor
, from
, to
-from
);
1817 ME_CommitUndo(editor
);
1818 ME_UpdateRepaint(editor
);
1825 LPWSTR wszText
= ME_ToUnicode(unicode
, (void *)lParam
);
1826 size_t len
= lstrlenW(wszText
);
1827 TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText
));
1829 ME_GetSelection(editor
, &from
, &to
);
1830 style
= ME_GetSelectionInsertStyle(editor
);
1831 ME_InternalDeleteText(editor
, from
, to
-from
);
1832 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, style
);
1833 ME_ReleaseStyle(style
);
1834 /* drop temporary style if line end */
1836 * FIXME question: does abc\n mean: put abc,
1837 * clear temp style, put \n? (would require a change)
1839 if (len
>0 && wszText
[len
-1] == '\n')
1840 ME_ClearTempStyle(editor
);
1841 ME_EndToUnicode(unicode
, wszText
);
1842 ME_CommitUndo(editor
);
1844 ME_EmptyUndoStack(editor
);
1845 ME_UpdateRepaint(editor
);
1848 case EM_SCROLLCARET
:
1850 int top
, bottom
; /* row's edges relative to document top */
1852 ME_DisplayItem
*para
, *row
;
1854 nPos
= ME_GetYScrollPos(editor
);
1855 row
= ME_RowStart(editor
->pCursors
[0].pRun
);
1856 para
= ME_GetParagraph(row
);
1857 top
= para
->member
.para
.nYPos
+ row
->member
.row
.nYPos
;
1858 bottom
= top
+ row
->member
.row
.nHeight
;
1860 if (top
< nPos
) /* caret above window */
1861 ME_ScrollAbs(editor
, top
);
1862 else if (nPos
+ editor
->sizeWindow
.cy
< bottom
) /*below*/
1863 ME_ScrollAbs(editor
, bottom
- editor
->sizeWindow
.cy
);
1871 BOOL bRepaint
= LOWORD(lParam
);
1874 wParam
= (WPARAM
)GetStockObject(SYSTEM_FONT
);
1875 GetObjectW((HGDIOBJ
)wParam
, sizeof(LOGFONTW
), &lf
);
1877 ME_CharFormatFromLogFont(hDC
, &lf
, &fmt
);
1878 ReleaseDC(hWnd
, hDC
);
1879 ME_SetCharFormat(editor
, 0, ME_GetTextLength(editor
), &fmt
);
1880 ME_SetDefaultCharFormat(editor
, &fmt
);
1882 ME_CommitUndo(editor
);
1884 ME_RewrapRepaint(editor
);
1889 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
));
1892 TRACE("WM_SETTEXT lParam==%lx\n",lParam
);
1893 if (!unicode
&& !strncmp((char *)lParam
, "{\\rtf", 5))
1895 /* Undocumented: WM_SETTEXT supports RTF text */
1896 ME_StreamInRTFString(editor
, 0, (char *)lParam
);
1900 LPWSTR wszText
= ME_ToUnicode(unicode
, (void *)lParam
);
1901 TRACE("WM_SETTEXT - %s\n", debugstr_w(wszText
)); /* debugstr_w() */
1902 if (lstrlenW(wszText
) > 0)
1904 /* uses default style! */
1905 ME_InsertTextFromCursor(editor
, 0, wszText
, -1, editor
->pBuffer
->pDefaultStyle
);
1907 ME_EndToUnicode(unicode
, wszText
);
1911 TRACE("WM_SETTEXT - NULL\n");
1912 ME_CommitUndo(editor
);
1913 ME_EmptyUndoStack(editor
);
1914 ME_SetSelection(editor
, 0, 0);
1915 ME_UpdateRepaint(editor
);
1920 UINT nRTFFormat
= RegisterClipboardFormatA("Rich Text Format");
1921 if (IsClipboardFormatAvailable(nRTFFormat
))
1923 if (IsClipboardFormatAvailable(CF_UNICODETEXT
))
1931 ME_GlobalDestStruct gds
;
1932 UINT nRTFFormat
= RegisterClipboardFormatA("Rich Text Format");
1935 if (IsClipboardFormatAvailable(nRTFFormat
))
1936 cf
= nRTFFormat
, dwFormat
= SF_RTF
;
1937 else if (IsClipboardFormatAvailable(CF_UNICODETEXT
))
1938 cf
= CF_UNICODETEXT
, dwFormat
= SF_TEXT
|SF_UNICODE
;
1942 if (!OpenClipboard(hWnd
))
1944 gds
.hData
= GetClipboardData(cf
);
1946 es
.dwCookie
= (DWORD
)&gds
;
1947 es
.pfnCallback
= dwFormat
== SF_RTF
? ME_ReadFromHGLOBALRTF
: ME_ReadFromHGLOBALUnicode
;
1948 ME_StreamIn(editor
, dwFormat
|SFF_SELECTION
, &es
);
1956 LPDATAOBJECT dataObj
= NULL
;
1960 if (editor
->cPasswordMask
)
1961 return 0; /* Copying or Cutting masked text isn't allowed */
1963 ME_GetSelection(editor
, (int*)&range
.cpMin
, (int*)&range
.cpMax
);
1964 if(editor
->lpOleCallback
)
1965 hr
= IRichEditOleCallback_GetClipboardData(editor
->lpOleCallback
, &range
, RECO_COPY
, &dataObj
);
1966 if(FAILED(hr
) || !dataObj
)
1967 hr
= ME_GetDataObject(editor
, &range
, &dataObj
);
1969 hr
= OleSetClipboard(dataObj
);
1970 IDataObject_Release(dataObj
);
1972 if (SUCCEEDED(hr
) && msg
== WM_CUT
)
1974 ME_InternalDeleteText(editor
, range
.cpMin
, range
.cpMax
-range
.cpMin
);
1975 ME_CommitUndo(editor
);
1976 ME_UpdateRepaint(editor
);
1980 case WM_GETTEXTLENGTH
:
1981 return ME_GetTextLength(editor
);
1982 case EM_GETTEXTLENGTHEX
:
1983 return ME_GetTextLengthEx(editor
, (GETTEXTLENGTHEX
*)wParam
);
1986 TEXTRANGEW tr
; /* W and A differ only by rng->lpstrText */
1988 tr
.chrg
.cpMax
= wParam
? (wParam
- 1) : 0;
1989 tr
.lpstrText
= (WCHAR
*)lParam
;
1990 return RichEditWndProc_common(hWnd
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
, unicode
);
1994 GETTEXTEX
*ex
= (GETTEXTEX
*)wParam
;
1997 if (ex
->flags
& ~(GT_SELECTION
| GT_USECRLF
))
1998 FIXME("GETTEXTEX flags 0x%08x not supported\n", ex
->flags
& ~(GT_SELECTION
| GT_USECRLF
));
2000 if (ex
->flags
& GT_SELECTION
)
2002 ME_GetSelection(editor
, &nStart
, &nCount
);
2004 nCount
= min(nCount
, ex
->cb
- 1);
2009 nCount
= ex
->cb
- 1;
2011 if (ex
->codepage
== 1200)
2013 nCount
= min(nCount
, ex
->cb
/ sizeof(WCHAR
) - 1);
2014 return ME_GetTextW(editor
, (LPWSTR
)lParam
, nStart
, nCount
, ex
->flags
& GT_USECRLF
);
2018 /* potentially each char may be a CR, why calculate the exact value with O(N) when
2019 we can just take a bigger buffer? :) */
2020 int crlfmul
= (ex
->flags
& GT_USECRLF
) ? 2 : 1;
2021 LPWSTR buffer
= richedit_alloc((crlfmul
*nCount
+ 1) * sizeof(WCHAR
));
2022 DWORD buflen
= ex
->cb
;
2026 buflen
= ME_GetTextW(editor
, buffer
, nStart
, nCount
, ex
->flags
& GT_USECRLF
);
2027 rc
= WideCharToMultiByte(ex
->codepage
, flags
, buffer
, -1, (LPSTR
)lParam
, ex
->cb
, ex
->lpDefaultChar
, ex
->lpUsedDefaultChar
);
2028 if (rc
) rc
--; /* do not count 0 terminator */
2030 richedit_free(buffer
);
2037 TEXTRANGEW tr
; /* W and A differ only by rng->lpstrText */
2038 ME_GetSelection(editor
, &from
, &to
);
2039 tr
.chrg
.cpMin
= from
;
2041 tr
.lpstrText
= (WCHAR
*)lParam
;
2042 return RichEditWndProc_common(hWnd
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
, unicode
);
2044 case EM_GETSCROLLPOS
:
2046 POINT
*point
= (POINT
*)lParam
;
2047 point
->x
= 0; /* FIXME side scrolling not implemented */
2048 point
->y
= ME_GetYScrollPos(editor
);
2051 case EM_GETTEXTRANGE
:
2053 TEXTRANGEW
*rng
= (TEXTRANGEW
*)lParam
;
2054 TRACE("EM_GETTEXTRANGE min=%d max=%d unicode=%d emul1.0=%d length=%d\n",
2055 rng
->chrg
.cpMin
, rng
->chrg
.cpMax
, unicode
,
2056 editor
->bEmulateVersion10
, ME_GetTextLength(editor
));
2058 return ME_GetTextW(editor
, rng
->lpstrText
, rng
->chrg
.cpMin
, rng
->chrg
.cpMax
-rng
->chrg
.cpMin
, editor
->bEmulateVersion10
);
2061 int nLen
= rng
->chrg
.cpMax
-rng
->chrg
.cpMin
;
2062 WCHAR
*p
= ALLOC_N_OBJ(WCHAR
, nLen
+1);
2063 int nChars
= ME_GetTextW(editor
, p
, rng
->chrg
.cpMin
, nLen
, editor
->bEmulateVersion10
);
2064 /* FIXME this is a potential security hole (buffer overrun)
2065 if you know more about wchar->mbyte conversion please explain
2067 WideCharToMultiByte(CP_ACP
, 0, p
, nChars
+1, (char *)rng
->lpstrText
, nLen
+1, NULL
, NULL
);
2074 ME_DisplayItem
*run
;
2075 const unsigned int nMaxChars
= *(WORD
*) lParam
;
2076 unsigned int nEndChars
, nCharsLeft
= nMaxChars
;
2077 char *dest
= (char *) lParam
;
2078 /* rich text editor 1.0 uses \r\n for line end, 2.0 uses just \r;
2079 we need to know how if we have the extra \n or not */
2080 int nLF
= editor
->bEmulateVersion10
;
2082 TRACE("EM_GETLINE: row=%d, nMaxChars=%d (%s)\n", (int) wParam
, nMaxChars
,
2083 unicode
? "Unicode" : "Ansi");
2085 run
= ME_FindRowWithNumber(editor
, wParam
);
2089 while (nCharsLeft
&& (run
= ME_FindItemFwd(run
, diRunOrStartRow
))
2090 && !(run
->member
.run
.nFlags
& MERF_ENDPARA
))
2094 if (run
->type
!= diRun
)
2096 strText
= run
->member
.run
.strText
;
2097 nCopy
= min(nCharsLeft
, strText
->nLen
);
2100 lstrcpynW((LPWSTR
) dest
, strText
->szData
, nCopy
);
2102 nCopy
= WideCharToMultiByte(CP_ACP
, 0, strText
->szData
, nCopy
, dest
,
2103 nCharsLeft
, NULL
, NULL
);
2104 dest
+= nCopy
* (unicode
? sizeof(WCHAR
) : 1);
2105 nCharsLeft
-= nCopy
;
2108 /* append \r\0 (or \r\n\0 in 1.0), space allowing */
2109 nEndChars
= min(nCharsLeft
, 2 + nLF
);
2110 nCharsLeft
-= nEndChars
;
2113 const WCHAR src
[] = {'\r', '\0'};
2114 const WCHAR src10
[] = {'\r', '\n', '\0'};
2115 lstrcpynW((LPWSTR
) dest
, nLF
? src10
: src
, nEndChars
);
2118 lstrcpynA(dest
, nLF
? "\r\n" : "\r", nEndChars
);
2120 TRACE("EM_GETLINE: got %u bytes\n", nMaxChars
- nCharsLeft
);
2122 if (nEndChars
== 2 + nLF
)
2123 return nMaxChars
- nCharsLeft
- 1; /* don't count \0 */
2125 return nMaxChars
- nCharsLeft
;
2127 case EM_GETLINECOUNT
:
2129 ME_DisplayItem
*item
= editor
->pBuffer
->pFirst
->next
;
2132 while (item
!= editor
->pBuffer
->pLast
)
2134 assert(item
->type
== diParagraph
);
2135 nRows
+= item
->member
.para
.nRows
;
2136 item
= item
->member
.para
.next_para
;
2138 TRACE("EM_GETLINECOUNT: nRows==%d\n", nRows
);
2139 return max(1, nRows
);
2141 case EM_LINEFROMCHAR
:
2144 return ME_RowNumberFromCharOfs(editor
, ME_GetCursorOfs(editor
, 1));
2146 return ME_RowNumberFromCharOfs(editor
, wParam
);
2148 case EM_EXLINEFROMCHAR
:
2151 return ME_RowNumberFromCharOfs(editor
, ME_GetCursorOfs(editor
,1));
2153 return ME_RowNumberFromCharOfs(editor
, lParam
);
2157 ME_DisplayItem
*item
, *para
;
2161 item
= ME_FindItemBack(editor
->pCursors
[0].pRun
, diStartRow
);
2163 item
= ME_FindRowWithNumber(editor
, wParam
);
2166 para
= ME_GetParagraph(item
);
2167 item
= ME_FindItemFwd(item
, diRun
);
2168 nCharOfs
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
;
2169 TRACE("EM_LINEINDEX: nCharOfs==%d\n", nCharOfs
);
2174 ME_DisplayItem
*item
, *item_end
;
2175 int nChars
= 0, nThisLineOfs
= 0, nNextLineOfs
= 0;
2177 if (wParam
> ME_GetTextLength(editor
))
2181 FIXME("EM_LINELENGTH: returning number of unselected characters on lines with selection unsupported.\n");
2184 item
= ME_FindItemAtOffset(editor
, diRun
, wParam
, NULL
);
2185 item
= ME_RowStart(item
);
2186 nThisLineOfs
= ME_CharOfsFromRunOfs(editor
, ME_FindItemFwd(item
, diRun
), 0);
2187 item_end
= ME_FindItemFwd(item
, diStartRowOrParagraphOrEnd
);
2188 if (item_end
->type
== diStartRow
)
2189 nNextLineOfs
= ME_CharOfsFromRunOfs(editor
, ME_FindItemFwd(item_end
, diRun
), 0);
2191 nNextLineOfs
= ME_FindItemFwd(item
, diParagraphOrEnd
)->member
.para
.nCharOfs
2192 - (editor
->bEmulateVersion10
?2:1);
2193 nChars
= nNextLineOfs
- nThisLineOfs
;
2194 TRACE("EM_LINELENGTH(%ld)==%d\n",wParam
, nChars
);
2197 case EM_EXLIMITTEXT
:
2199 if ((int)lParam
< 0)
2202 editor
->nTextLimit
= 65536;
2204 editor
->nTextLimit
= (int) lParam
;
2210 editor
->nTextLimit
= 65536;
2212 editor
->nTextLimit
= (int) wParam
;
2215 case EM_GETLIMITTEXT
:
2217 return editor
->nTextLimit
;
2221 FINDTEXTA
*ft
= (FINDTEXTA
*)lParam
;
2222 int nChars
= MultiByteToWideChar(CP_ACP
, 0, ft
->lpstrText
, -1, NULL
, 0);
2226 if ((tmp
= ALLOC_N_OBJ(WCHAR
, nChars
)) != NULL
)
2227 MultiByteToWideChar(CP_ACP
, 0, ft
->lpstrText
, -1, tmp
, nChars
);
2228 r
= ME_FindText(editor
, wParam
, &ft
->chrg
, tmp
, NULL
);
2234 FINDTEXTEXA
*ex
= (FINDTEXTEXA
*)lParam
;
2235 int nChars
= MultiByteToWideChar(CP_ACP
, 0, ex
->lpstrText
, -1, NULL
, 0);
2239 if ((tmp
= ALLOC_N_OBJ(WCHAR
, nChars
)) != NULL
)
2240 MultiByteToWideChar(CP_ACP
, 0, ex
->lpstrText
, -1, tmp
, nChars
);
2241 r
= ME_FindText(editor
, wParam
, &ex
->chrg
, tmp
, &ex
->chrgText
);
2247 FINDTEXTW
*ft
= (FINDTEXTW
*)lParam
;
2248 return ME_FindText(editor
, wParam
, &ft
->chrg
, ft
->lpstrText
, NULL
);
2250 case EM_FINDTEXTEXW
:
2252 FINDTEXTEXW
*ex
= (FINDTEXTEXW
*)lParam
;
2253 return ME_FindText(editor
, wParam
, &ex
->chrg
, ex
->lpstrText
, &ex
->chrgText
);
2256 if (!wParam
|| !lParam
)
2258 *(int *)wParam
= editor
->nZoomNumerator
;
2259 *(int *)lParam
= editor
->nZoomDenominator
;
2262 return ME_SetZoom(editor
, wParam
, lParam
);
2263 case EM_CHARFROMPOS
:
2264 return ME_CharFromPos(editor
, ((POINTL
*)lParam
)->x
, ((POINTL
*)lParam
)->y
);
2265 case EM_POSFROMCHAR
:
2267 ME_DisplayItem
*pRun
;
2268 int nCharOfs
, nOffset
, nLength
;
2272 /* detect which API version we're dealing with */
2273 if (wParam
>= 0x40000)
2275 nLength
= ME_GetTextLength(editor
);
2277 if (nCharOfs
< nLength
) {
2278 ME_RunOfsFromCharOfs(editor
, nCharOfs
, &pRun
, &nOffset
);
2279 assert(pRun
->type
== diRun
);
2280 pt
.y
= pRun
->member
.run
.pt
.y
;
2281 pt
.x
= pRun
->member
.run
.pt
.x
+ ME_PointFromChar(editor
, &pRun
->member
.run
, nOffset
);
2282 pt
.y
+= ME_GetParagraph(pRun
)->member
.para
.nYPos
;
2285 pt
.y
= editor
->pBuffer
->pLast
->member
.para
.nYPos
;
2287 if (wParam
>= 0x40000) {
2288 *(POINTL
*)wParam
= pt
;
2290 return MAKELONG( pt
.x
, pt
.y
);
2293 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_HSCROLL
)
2294 { /* Squelch the default horizontal scrollbar it would make */
2295 ShowScrollBar(editor
->hWnd
, SB_HORZ
, FALSE
);
2297 ME_CommitUndo(editor
);
2298 ME_WrapMarkedParagraphs(editor
);
2299 ME_MoveCaret(editor
);
2302 ME_DestroyEditor(editor
);
2303 SetWindowLongPtrW(hWnd
, 0, 0);
2305 case WM_LBUTTONDOWN
:
2307 ME_LButtonDown(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
2309 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
2312 if (GetCapture() == hWnd
)
2313 ME_MouseMove(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
2314 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
2317 if (GetCapture() == hWnd
)
2319 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
2321 case WM_LBUTTONDBLCLK
:
2322 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
2323 ME_SelectWord(editor
);
2325 case WM_CONTEXTMENU
:
2326 if (!ME_ShowContextMenu(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
)))
2330 if (editor
->bRedraw
)
2335 hDC
= BeginPaint(hWnd
, &ps
);
2336 ME_PaintContent(editor
, hDC
, FALSE
, &ps
.rcPaint
);
2337 EndPaint(hWnd
, &ps
);
2341 editor
->bHaveFocus
= TRUE
;
2342 ME_ShowCaret(editor
);
2343 ME_SendOldNotify(editor
, EN_SETFOCUS
);
2346 ME_HideCaret(editor
);
2347 editor
->bHaveFocus
= FALSE
;
2348 ME_SendOldNotify(editor
, EN_KILLFOCUS
);
2352 if (editor
->bRedraw
)
2354 HDC hDC
= (HDC
)wParam
;
2356 if (GetUpdateRect(hWnd
,&rc
,TRUE
))
2358 FillRect(hDC
, &rc
, editor
->hbrBackground
);
2364 TRACE("editor wnd command = %d\n", LOWORD(wParam
));
2367 if (ME_KeyDown(editor
, LOWORD(wParam
)))
2375 wstr
= (WCHAR
)wParam
;
2378 CHAR charA
= wParam
;
2379 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &wstr
, 1);
2381 if (editor
->AutoURLDetect_bEnable
)
2382 ME_AutoURLDetect(editor
, wstr
);
2386 case 1: /* Ctrl-A */
2387 ME_SetSelection(editor
, 0, -1);
2389 case 3: /* Ctrl-C */
2390 SendMessageW(editor
->hWnd
, WM_COPY
, 0, 0);
2394 if (GetWindowLongW(editor
->hWnd
, GWL_STYLE
) & ES_READONLY
) {
2395 MessageBeep(MB_ICONERROR
);
2396 return 0; /* FIXME really 0 ? */
2401 case 22: /* Ctrl-V */
2402 SendMessageW(editor
->hWnd
, WM_PASTE
, 0, 0);
2404 case 24: /* Ctrl-X */
2405 SendMessageW(editor
->hWnd
, WM_CUT
, 0, 0);
2407 case 25: /* Ctrl-Y */
2408 SendMessageW(editor
->hWnd
, EM_REDO
, 0, 0);
2410 case 26: /* Ctrl-Z */
2411 SendMessageW(editor
->hWnd
, EM_UNDO
, 0, 0);
2414 if (((unsigned)wstr
)>=' ' || wstr
=='\r' || wstr
=='\t') {
2415 /* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */
2416 ME_Style
*style
= ME_GetInsertStyle(editor
, 0);
2417 ME_SaveTempStyle(editor
);
2418 ME_InsertTextFromCursor(editor
, 0, &wstr
, 1, style
);
2419 ME_ReleaseStyle(style
);
2420 ME_CommitUndo(editor
);
2421 ME_UpdateRepaint(editor
);
2425 case EM_SCROLL
: /* fall through */
2431 origNPos
= ME_GetYScrollPos(editor
);
2434 if (editor
&& editor
->pBuffer
&& editor
->pBuffer
->pDefaultStyle
)
2435 lineHeight
= editor
->pBuffer
->pDefaultStyle
->tm
.tmHeight
;
2436 if (lineHeight
<= 0) lineHeight
= 24;
2438 switch(LOWORD(wParam
))
2441 ME_ScrollUp(editor
,lineHeight
);
2444 ME_ScrollDown(editor
,lineHeight
);
2447 ME_ScrollUp(editor
,editor
->sizeWindow
.cy
);
2450 ME_ScrollDown(editor
,editor
->sizeWindow
.cy
);
2453 case SB_THUMBPOSITION
:
2454 ME_ScrollAbs(editor
,HIWORD(wParam
));
2457 if (msg
== EM_SCROLL
)
2458 return 0x00010000 | (((ME_GetYScrollPos(editor
) - origNPos
)/lineHeight
) & 0xffff);
2464 UINT pulScrollLines
;
2466 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
2467 gcWheelDelta
= -GET_WHEEL_DELTA_WPARAM(wParam
);
2469 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
2471 /* FIXME follow the original */
2472 ME_ScrollDown(editor
,pulScrollLines
* (gcWheelDelta
/ WHEEL_DELTA
) * 8);
2478 *((RECT
*)lParam
) = editor
->rcFormat
;
2486 RECT
*rc
= (RECT
*)lParam
;
2490 editor
->rcFormat
.left
+= rc
->left
;
2491 editor
->rcFormat
.top
+= rc
->top
;
2492 editor
->rcFormat
.right
+= rc
->right
;
2493 editor
->rcFormat
.bottom
+= rc
->bottom
;
2497 editor
->rcFormat
= *rc
;
2502 GetClientRect(hWnd
, &editor
->rcFormat
);
2504 if (msg
!= EM_SETRECTNP
)
2505 ME_RewrapRepaint(editor
);
2508 case EM_REQUESTRESIZE
:
2509 ME_SendRequestResize(editor
, TRUE
);
2512 editor
->bRedraw
= wParam
;
2516 GetClientRect(hWnd
, &editor
->rcFormat
);
2517 ME_RewrapRepaint(editor
);
2518 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2520 /* IME messages to make richedit controls IME aware */
2521 case WM_IME_SETCONTEXT
:
2522 case WM_IME_CONTROL
:
2524 case WM_IME_COMPOSITIONFULL
:
2526 case WM_IME_STARTCOMPOSITION
:
2528 editor
->imeStartIndex
=ME_GetCursorOfs(editor
,0);
2529 ME_DeleteSelection(editor
);
2530 ME_CommitUndo(editor
);
2531 ME_UpdateRepaint(editor
);
2534 case WM_IME_COMPOSITION
:
2538 ME_Style
*style
= ME_GetInsertStyle(editor
, 0);
2539 hIMC
= ImmGetContext(hWnd
);
2540 ME_DeleteSelection(editor
);
2541 ME_CommitUndo(editor
);
2542 ME_SaveTempStyle(editor
);
2543 if (lParam
& GCS_RESULTSTR
)
2545 LPWSTR lpCompStr
= NULL
;
2548 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
2549 lpCompStr
= HeapAlloc(GetProcessHeap(),0,dwBufLen
+ sizeof(WCHAR
));
2550 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpCompStr
, dwBufLen
);
2551 lpCompStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
2552 ME_InsertTextFromCursor(editor
,0,lpCompStr
,dwBufLen
/sizeof(WCHAR
),style
);
2554 else if (lParam
& GCS_COMPSTR
)
2556 LPWSTR lpCompStr
= NULL
;
2559 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
2560 lpCompStr
= HeapAlloc(GetProcessHeap(),0,dwBufLen
+ sizeof(WCHAR
));
2561 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, dwBufLen
);
2562 lpCompStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
2564 ME_InsertTextFromCursor(editor
,0,lpCompStr
,dwBufLen
/sizeof(WCHAR
),style
);
2565 ME_SetSelection(editor
,editor
->imeStartIndex
,
2566 editor
->imeStartIndex
+ dwBufLen
/sizeof(WCHAR
));
2568 ME_ReleaseStyle(style
);
2569 ME_UpdateRepaint(editor
);
2572 case WM_IME_ENDCOMPOSITION
:
2574 ME_DeleteSelection(editor
);
2575 editor
->imeStartIndex
=-1;
2578 case EM_GETOLEINTERFACE
:
2580 LPVOID
*ppvObj
= (LPVOID
*) lParam
;
2581 return CreateIRichEditOle(editor
, ppvObj
);
2583 case EM_GETPASSWORDCHAR
:
2585 return editor
->cPasswordMask
;
2587 case EM_SETOLECALLBACK
:
2588 if(editor
->lpOleCallback
)
2589 IUnknown_Release(editor
->lpOleCallback
);
2590 editor
->lpOleCallback
= (LPRICHEDITOLECALLBACK
)lParam
;
2591 if(editor
->lpOleCallback
)
2592 IUnknown_AddRef(editor
->lpOleCallback
);
2594 case EM_GETWORDBREAKPROC
:
2595 return (LRESULT
)editor
->pfnWordBreak
;
2596 case EM_SETWORDBREAKPROC
:
2598 EDITWORDBREAKPROCW pfnOld
= editor
->pfnWordBreak
;
2600 editor
->pfnWordBreak
= (EDITWORDBREAKPROCW
)lParam
;
2601 return (LRESULT
)pfnOld
;
2603 case EM_SETTEXTMODE
:
2608 ret
= RichEditWndProc_common(hWnd
, WM_GETTEXTLENGTH
, 0, 0, unicode
);
2611 /*Check for valid wParam*/
2612 if ((((wParam
& TM_RICHTEXT
) && ((wParam
& TM_PLAINTEXT
) << 1))) ||
2613 (((wParam
& TM_MULTILEVELUNDO
) && ((wParam
& TM_SINGLELEVELUNDO
) << 1))) ||
2614 (((wParam
& TM_MULTICODEPAGE
) && ((wParam
& TM_SINGLECODEPAGE
) << 1))))
2618 if (wParam
& (TM_RICHTEXT
| TM_PLAINTEXT
))
2620 mask
|= (TM_RICHTEXT
| TM_PLAINTEXT
);
2621 changes
|= (wParam
& (TM_RICHTEXT
| TM_PLAINTEXT
));
2623 /*FIXME: Currently no support for undo level and code page options*/
2624 editor
->mode
= (editor
->mode
& (~mask
)) | changes
;
2630 case EM_SETPASSWORDCHAR
:
2632 editor
->cPasswordMask
= wParam
;
2633 ME_RewrapRepaint(editor
);
2638 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2643 static LRESULT WINAPI
RichEditWndProcW(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2645 BOOL unicode
= TRUE
;
2647 /* Under Win9x RichEdit20W returns ANSI strings, see the tests. */
2648 if (msg
== WM_GETTEXT
&& (GetVersion() & 0x80000000))
2651 return RichEditWndProc_common(hWnd
, msg
, wParam
, lParam
, unicode
);
2654 static LRESULT WINAPI
RichEditWndProcA(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2656 return RichEditWndProc_common(hWnd
, msg
, wParam
, lParam
, FALSE
);
2659 /******************************************************************
2660 * RichEditANSIWndProc (RICHED20.10)
2662 LRESULT WINAPI
RichEditANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2664 return RichEditWndProcA(hWnd
, msg
, wParam
, lParam
);
2667 /******************************************************************
2668 * RichEdit10ANSIWndProc (RICHED20.9)
2670 LRESULT WINAPI
RichEdit10ANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2674 /* FIXME: this is NOT the same as 2.0 version */
2675 result
= RichEditANSIWndProc(hWnd
, msg
, wParam
, lParam
);
2676 if (msg
== WM_NCCREATE
)
2678 ME_TextEditor
*editor
= (ME_TextEditor
*)GetWindowLongPtrW(hWnd
, 0);
2680 editor
->bEmulateVersion10
= TRUE
;
2681 editor
->pBuffer
->pLast
->member
.para
.nCharOfs
= 2;
2686 void ME_SendOldNotify(ME_TextEditor
*editor
, int nCode
)
2688 HWND hWnd
= editor
->hWnd
;
2689 SendMessageA(GetParent(hWnd
), WM_COMMAND
, (nCode
<<16)|GetWindowLongW(hWnd
, GWLP_ID
), (LPARAM
)hWnd
);
2692 void ME_LinkNotify(ME_TextEditor
*editor
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2695 ME_Cursor tmpCursor
;
2696 int nCharOfs
; /* The start of the clicked text. Absolute character offset */
2701 x
= (short)LOWORD(lParam
);
2702 y
= (short)HIWORD(lParam
);
2703 nCharOfs
= ME_CharFromPos(editor
, x
, y
);
2704 if (nCharOfs
< 0) return;
2706 ME_CursorFromCharOfs(editor
, nCharOfs
, &tmpCursor
);
2707 tmpRun
= &tmpCursor
.pRun
->member
.run
;
2709 if ((tmpRun
->style
->fmt
.dwMask
& CFM_LINK
)
2710 && (tmpRun
->style
->fmt
.dwEffects
& CFE_LINK
))
2711 { /* The clicked run has CFE_LINK set */
2712 info
.nmhdr
.hwndFrom
= editor
->hWnd
;
2713 info
.nmhdr
.idFrom
= GetWindowLongW(editor
->hWnd
, GWLP_ID
);
2714 info
.nmhdr
.code
= EN_LINK
;
2716 info
.wParam
= wParam
;
2717 info
.lParam
= lParam
;
2718 info
.chrg
.cpMin
= ME_CharOfsFromRunOfs(editor
,tmpCursor
.pRun
,0);
2719 info
.chrg
.cpMax
= info
.chrg
.cpMin
+ ME_StrVLen(tmpRun
->strText
);
2720 SendMessageW(GetParent(editor
->hWnd
), WM_NOTIFY
,info
.nmhdr
.idFrom
, (LPARAM
)&info
);
2724 int ME_CountParagraphsBetween(ME_TextEditor
*editor
, int from
, int to
)
2726 ME_DisplayItem
*item
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
2729 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= from
)
2730 item
= item
->member
.para
.next_para
;
2733 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= to
) {
2734 item
= item
->member
.para
.next_para
;
2741 int ME_GetTextW(ME_TextEditor
*editor
, WCHAR
*buffer
, int nStart
, int nChars
, int bCRLF
)
2743 ME_DisplayItem
*item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
2745 WCHAR
*pStart
= buffer
;
2754 int nLen
= ME_StrLen(item
->member
.run
.strText
) - nStart
;
2757 CopyMemory(buffer
, item
->member
.run
.strText
->szData
+ nStart
, sizeof(WCHAR
)*nLen
);
2764 item
= ME_FindItemFwd(item
, diRun
);
2767 while(nChars
&& item
)
2769 int nLen
= ME_StrLen(item
->member
.run
.strText
);
2773 if (item
->member
.run
.nFlags
& MERF_ENDPARA
)
2775 if (!ME_FindItemFwd(item
, diRun
))
2776 /* No '\r' is appended to the last paragraph. */
2786 /* our end paragraph consists of 2 characters now */
2787 if (editor
->bEmulateVersion10
)
2792 CopyMemory(buffer
, item
->member
.run
.strText
->szData
, sizeof(WCHAR
)*nLen
);
2799 TRACE("nWritten=%d, actual=%d\n", nWritten
, buffer
-pStart
);
2803 item
= ME_FindItemFwd(item
, diRun
);
2806 TRACE("nWritten=%d, actual=%d\n", nWritten
, buffer
-pStart
);
2810 static BOOL
ME_RegisterEditorClass(HINSTANCE hInstance
)
2815 wcW
.style
= CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
;
2816 wcW
.lpfnWndProc
= RichEditWndProcW
;
2818 wcW
.cbWndExtra
= sizeof(ME_TextEditor
*);
2819 wcW
.hInstance
= NULL
; /* hInstance would register DLL-local class */
2821 wcW
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
2822 wcW
.hbrBackground
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
2823 wcW
.lpszMenuName
= NULL
;
2825 if (is_version_nt())
2827 wcW
.lpszClassName
= RichEdit20W
;
2828 if (!RegisterClassW(&wcW
)) return FALSE
;
2829 wcW
.lpszClassName
= RichEdit50W
;
2830 if (!RegisterClassW(&wcW
)) return FALSE
;
2834 /* WNDCLASSA/W have the same layout */
2835 wcW
.lpszClassName
= (LPCWSTR
)"RichEdit20W";
2836 if (!RegisterClassA((WNDCLASSA
*)&wcW
)) return FALSE
;
2837 wcW
.lpszClassName
= (LPCWSTR
)"RichEdit50W";
2838 if (!RegisterClassA((WNDCLASSA
*)&wcW
)) return FALSE
;
2841 wcA
.style
= CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
;
2842 wcA
.lpfnWndProc
= RichEditWndProcA
;
2844 wcA
.cbWndExtra
= sizeof(ME_TextEditor
*);
2845 wcA
.hInstance
= NULL
; /* hInstance would register DLL-local class */
2847 wcA
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
2848 wcA
.hbrBackground
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
2849 wcA
.lpszMenuName
= NULL
;
2850 wcA
.lpszClassName
= "RichEdit20A";
2851 if (!RegisterClassA(&wcA
)) return FALSE
;
2852 wcA
.lpszClassName
= "RichEdit50A";
2853 if (!RegisterClassA(&wcA
)) return FALSE
;
2858 LRESULT WINAPI
REComboWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
) {
2859 /* FIXME: Not implemented */
2860 TRACE("hWnd %p msg %04x (%s) %08lx %08lx\n",
2861 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
);
2862 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2865 LRESULT WINAPI
REListWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
) {
2866 /* FIXME: Not implemented */
2867 TRACE("hWnd %p msg %04x (%s) %08lx %08lx\n",
2868 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
);
2869 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2872 /******************************************************************
2873 * REExtendedRegisterClass (RICHED20.8)
2875 * FIXME undocumented
2876 * Need to check for errors and implement controls and callbacks
2878 LRESULT WINAPI
REExtendedRegisterClass(void)
2883 FIXME("semi stub\n");
2887 wcW
.hInstance
= NULL
;
2890 wcW
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
2891 wcW
.lpszMenuName
= NULL
;
2893 if (!ME_ListBoxRegistered
)
2895 wcW
.style
= CS_PARENTDC
| CS_DBLCLKS
| CS_GLOBALCLASS
;
2896 wcW
.lpfnWndProc
= REListWndProc
;
2897 wcW
.lpszClassName
= REListBox20W
;
2898 if (RegisterClassW(&wcW
)) ME_ListBoxRegistered
= TRUE
;
2901 if (!ME_ComboBoxRegistered
)
2903 wcW
.style
= CS_PARENTDC
| CS_DBLCLKS
| CS_GLOBALCLASS
| CS_VREDRAW
| CS_HREDRAW
;
2904 wcW
.lpfnWndProc
= REComboWndProc
;
2905 wcW
.lpszClassName
= REComboBox20W
;
2906 if (RegisterClassW(&wcW
)) ME_ComboBoxRegistered
= TRUE
;
2910 if (ME_ListBoxRegistered
)
2912 if (ME_ComboBoxRegistered
)
2918 int ME_AutoURLDetect(ME_TextEditor
*editor
, WCHAR curChar
)
2938 int curf_ef
, link_ef
, def_ef
;
2939 int cur_prefx
, prefx_cnt
;
2940 int sel_min
, sel_max
;
2943 int URLmin
, URLmax
= 0;
2946 CHARFORMAT2W cur_format
;
2947 CHARFORMAT2W default_format
;
2949 RichEditANSIWndProc(editor
->hWnd
, EM_EXGETSEL
, (WPARAM
) 0, (LPARAM
) &ins_pt
);
2950 sel_min
= ins_pt
.cpMin
;
2951 sel_max
= ins_pt
.cpMax
;
2952 if (sel_min
==sel_max
)
2954 if (sel_min
!=sel_max
)
2955 car_pos
= ME_GetTextLength(editor
)+1;
2956 cur_format
.cbSize
= sizeof(cur_format
);
2957 default_format
.cbSize
= sizeof(default_format
);
2958 RichEditANSIWndProc(editor
->hWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cur_format
);
2959 RichEditANSIWndProc(editor
->hWnd
, EM_GETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
) &default_format
);
2960 link
.cbSize
= sizeof(link
);
2961 link
.dwMask
= CFM_LINK
;
2962 link
.dwEffects
= CFE_LINK
;
2963 curf_ef
= cur_format
.dwEffects
& link
.dwEffects
;
2964 def_ef
= default_format
.dwEffects
& link
.dwEffects
;
2965 link_ef
= link
.dwEffects
& link
.dwEffects
;
2966 if (curf_ef
== link_ef
)
2968 if( curChar
== '\n' || curChar
=='\r' || curChar
==' ')
2970 ME_SetSelection(editor
, car_pos
, car_pos
);
2971 RichEditANSIWndProc(editor
->hWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &default_format
);
2976 if (curf_ef
== def_ef
)
2979 prefx_cnt
= (sizeof(prefixes
)/sizeof(struct prefix_s
))-1;
2980 while (cur_prefx
<=prefx_cnt
)
2984 ft
.lpstrText
= prefixes
[cur_prefx
].text
;
2985 URLmin
=max(0,(car_pos
-prefixes
[cur_prefx
].length
));
2986 URLmax
=max(0, car_pos
);
2987 if ((car_pos
== 0) && (ME_GetTextLength(editor
) != 0))
2989 URLmax
= ME_GetTextLength(editor
)+1;
2991 ft
.chrg
.cpMin
= URLmin
;
2992 ft
.chrg
.cpMax
= URLmax
;
2993 text_pos
=RichEditANSIWndProc(editor
->hWnd
, EM_FINDTEXT
, FR_DOWN
, (LPARAM
)&ft
);
2999 url
.cpMax
=car_pos
-1;
3000 ME_SetCharFormat(editor
, text_pos
, (URLmax
-text_pos
), &link
);
3001 ME_RewrapRepaint(editor
);