2 * RichEdit - functions dealing with editor object
4 * Copyright 2004 by Krzysztof Foltman
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 API implementation status:
24 Messages (ANSI versions not done yet)
25 - EM_AUTOURLDETECT 2.0
36 + EM_FINDTEXT (only FR_DOWN flag implemented)
37 + EM_FINDTEXTEX (only FR_DOWN flag implemented)
41 - EM_GETAUTOURLDETECT 2.0
42 - EM_GETBIDIOPTIONS 3.0
43 - EM_GETCHARFORMAT (partly done)
46 - EM_GETFIRSTVISIBLELINE
47 - EM_GETIMECOLOR 1.0asian
48 - EM_GETIMECOMPMODE 2.0
49 - EM_GETIMEOPTIONS 1.0asian
51 - EM_GETLANGOPTIONS 2.0
54 + EM_GETLINECOUNT returns number of rows, not of paragraphs
59 - EM_GETPASSWORDCHAR 2.0
60 - EM_GETPUNCTUATION 1.0asian
64 + EM_GETSELTEXT (ANSI&Unicode)
68 + EM_GETTEXTLENGTHEX (GTL_PRECISE unimplemented)
70 ? + EM_GETTEXTRANGE (ANSI&Unicode)
71 - EM_GETTYPOGRAPHYOPTIONS 3.0
74 - EM_GETWORDBREAKPROCEX
75 - EM_GETWORDWRAPMODE 1.0asian
87 + EM_REPLACESEL (proper style?) ANSI&Unicode
91 - EM_SETBIDIOPTIONS 3.0
93 - EM_SETCHARFORMAT (partly done, no ANSI)
95 + EM_SETEVENTMASK (few notifications supported)
97 - EM_SETIMECOLOR 1.0asian
98 - EM_SETIMEOPTIONS 1.0asian
99 - EM_SETLANGOPTIONS 2.0
101 + EM_SETMODIFY (not sure if implementation is correct)
106 - EM_SETPASSWORDCHAR 2.0
107 - EM_SETPUNCTUATION 1.0asian
108 + EM_SETREADONLY no beep on modification attempt
110 - EM_SETRECTNP (EM_SETRECT without repainting) - not supported in RICHEDIT
112 - EM_SETSCROLLPOS 3.0
115 + EM_SETTEXTEX 3.0 (unicode only, no rich text insertion handling, proper style?)
117 - EM_SETTYPOGRAPHYOPTIONS 3.0
118 - EM_SETUNDOLIMIT 2.0
119 - EM_SETWORDBREAKPROC
120 - EM_SETWORDBREAKPROCEX
121 - EM_SETWORDWRAPMODE 1.0asian
123 - EM_SHOWSCROLLBAR 2.0
124 - EM_STOPGROUPTYPING 2.0
132 + WM_GETDLGCODE (the current implementation is incomplete)
133 + WM_GETTEXT (ANSI&Unicode)
134 + WM_GETTEXTLENGTH (ANSI version sucks)
137 + WM_SETTEXT (resets undo stack !) (proper style?) ANSI&Unicode
139 - WM_STYLECHANGED (things like read-only flag)
144 * EN_CHANGE (sent from the wrong place)
161 * EN_UPDATE (sent from the wrong place)
169 - ES_DISABLENOSCROLL (scrollbar is always visible)
170 - ES_EX_NOCALLOLEINIT
172 - ES_MULTILINE (currently single line controls aren't supported)
174 - ES_READONLY (I'm not sure if beeping is the proper behaviour)
180 - ES_WANTRETURN (don't know how to do WM_GETDLGCODE part)
187 * RICHED20 TODO (incomplete):
189 * - messages/styles/notifications listed above
191 * - add remaining CHARFORMAT/PARAFORMAT fields
192 * - right/center align should strip spaces from the beginning
193 * - more advanced navigation (Ctrl-arrows)
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
212 * Bugs that are probably fixed, but not so easy to verify:
213 * - EN_UPDATE/EN_CHANGE are handled very incorrectly (should be OK now)
214 * - undo for ME_JoinParagraphs doesn't store paragraph format ? (it does)
215 * - check/fix artificial EOL logic (bCursorAtEnd, hardly logical)
216 * - caret shouldn't be displayed when selection isn't empty
217 * - check refcounting in style management functions (looks perfect now, but no bugs is suspicious)
218 * - undo for setting default format (done, might be buggy)
219 * - styles might be not released properly (looks like they work like charm, but who knows?
228 #define NO_SHLWAPI_STREAM
233 WINE_DEFAULT_DEBUG_CHANNEL(richedit
);
236 HANDLE me_heap
= NULL
;
238 static ME_TextBuffer
*ME_MakeText(void) {
240 ME_TextBuffer
*buf
= ALLOC_OBJ(ME_TextBuffer
);
242 ME_DisplayItem
*p1
= ME_MakeDI(diTextStart
);
243 ME_DisplayItem
*p2
= ME_MakeDI(diTextEnd
);
249 p1
->member
.para
.next_para
= p2
;
250 p2
->member
.para
.prev_para
= p1
;
251 p2
->member
.para
.nCharOfs
= 0;
255 buf
->pCharStyle
= NULL
;
261 static LRESULT
ME_StreamInText(ME_TextEditor
*editor
, DWORD dwFormat
, ME_InStream
*stream
, ME_Style
*style
)
263 WCHAR wszText
[STREAMIN_BUFFER_SIZE
+1];
266 TRACE("%08lx %p\n", dwFormat
, stream
);
273 ME_StreamInFill(stream
);
274 if (stream
->editstream
->dwError
)
280 if (!(dwFormat
& SF_UNICODE
))
282 /* FIXME? this is doomed to fail on true MBCS like UTF-8, luckily they're unlikely to be used as CP_ACP */
283 nWideChars
= MultiByteToWideChar(CP_ACP
, 0, stream
->buffer
, stream
->dwSize
, wszText
, STREAMIN_BUFFER_SIZE
);
288 nWideChars
= stream
->dwSize
>> 1;
289 pText
= (WCHAR
*)stream
->buffer
;
292 ME_InsertTextFromCursor(editor
, 0, pText
, nWideChars
, style
);
293 if (stream
->dwSize
< STREAMIN_BUFFER_SIZE
)
297 ME_CommitUndo(editor
);
302 static void ME_RTFCharAttrHook(RTF_Info
*info
)
305 fmt
.cbSize
= sizeof(fmt
);
308 switch(info
->rtfMinor
)
311 /* FIXME add more flags once they're implemented */
312 fmt
.dwMask
= CFM_BOLD
| CFM_ITALIC
| CFM_UNDERLINE
| CFM_STRIKEOUT
| CFM_COLOR
| CFM_BACKCOLOR
| CFM_SIZE
| CFM_WEIGHT
;
313 fmt
.dwEffects
= CFE_AUTOCOLOR
| CFE_AUTOBACKCOLOR
;
314 fmt
.yHeight
= 12*20; /* 12pt */
318 fmt
.dwMask
= CFM_BOLD
;
319 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
322 fmt
.dwMask
= CFM_ITALIC
;
323 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
326 fmt
.dwMask
= CFM_UNDERLINE
;
327 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
328 fmt
.bUnderlineType
= CFU_CF1UNDERLINE
;
331 fmt
.dwMask
= CFM_UNDERLINE
;
335 fmt
.dwMask
= CFM_STRIKEOUT
;
336 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
340 case rtfSubScrShrink
:
341 case rtfSuperScrShrink
:
343 fmt
.dwMask
= CFM_SUBSCRIPT
|CFM_SUPERSCRIPT
;
344 if (info
->rtfMinor
== rtfSubScrShrink
) fmt
.dwEffects
= CFE_SUBSCRIPT
;
345 if (info
->rtfMinor
== rtfSuperScrShrink
) fmt
.dwEffects
= CFE_SUPERSCRIPT
;
346 if (info
->rtfMinor
== rtfNoSuperSub
) fmt
.dwEffects
= 0;
349 fmt
.dwMask
= CFM_BACKCOLOR
;
351 if (info
->rtfParam
== 0)
352 fmt
.dwEffects
= CFE_AUTOBACKCOLOR
;
353 else if (info
->rtfParam
!= rtfNoParam
)
355 RTFColor
*c
= RTFGetColor(info
, info
->rtfParam
);
356 fmt
.crTextColor
= (c
->rtfCBlue
<<16)|(c
->rtfCGreen
<<8)|(c
->rtfCRed
);
360 fmt
.dwMask
= CFM_COLOR
;
362 if (info
->rtfParam
== 0)
363 fmt
.dwEffects
= CFE_AUTOCOLOR
;
364 else if (info
->rtfParam
!= rtfNoParam
)
366 RTFColor
*c
= RTFGetColor(info
, info
->rtfParam
);
367 fmt
.crTextColor
= (c
->rtfCBlue
<<16)|(c
->rtfCGreen
<<8)|(c
->rtfCRed
);
371 if (info
->rtfParam
!= rtfNoParam
)
373 RTFFont
*f
= RTFGetFont(info
, info
->rtfParam
);
376 MultiByteToWideChar(CP_ACP
, 0, f
->rtfFName
, -1, fmt
.szFaceName
, sizeof(fmt
.szFaceName
)/sizeof(WCHAR
));
377 fmt
.szFaceName
[sizeof(fmt
.szFaceName
)/sizeof(WCHAR
)-1] = '\0';
378 fmt
.bCharSet
= f
->rtfFCharSet
;
379 fmt
.dwMask
= CFM_FACE
| CFM_CHARSET
;
384 fmt
.dwMask
= CFM_SIZE
;
385 if (info
->rtfParam
!= rtfNoParam
)
386 fmt
.yHeight
= info
->rtfParam
*10;
391 RTFFlushOutputBuffer(info
);
392 /* FIXME too slow ? how come ? */
393 style2
= ME_ApplyStyle(info
->style
, &fmt
);
394 ME_ReleaseStyle(info
->style
);
395 info
->style
= style2
;
399 /* FIXME this function doesn't get any information about context of the RTF tag, which is very bad,
400 the same tags mean different things in different contexts */
401 static void ME_RTFParAttrHook(RTF_Info
*info
)
404 fmt
.cbSize
= sizeof(fmt
);
407 switch(info
->rtfMinor
)
409 case rtfParDef
: /* I'm not 100% sure what does it do, but I guess it restores default paragraph attributes */
410 fmt
.dwMask
= PFM_ALIGNMENT
| PFM_TABSTOPS
| PFM_OFFSET
| PFM_STARTINDENT
;
411 fmt
.wAlignment
= PFA_LEFT
;
413 fmt
.dxOffset
= fmt
.dxStartIndent
= 0;
416 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
417 fmt
.dwMask
= PFM_STARTINDENT
;
418 fmt
.dxStartIndent
= info
->rtfParam
+ fmt
.dxOffset
;
423 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
424 first
= fmt
.dxStartIndent
;
425 left
= info
->rtfParam
;
426 fmt
.dwMask
= PFM_STARTINDENT
|PFM_OFFSET
;
427 fmt
.dxStartIndent
= first
+ left
;
428 fmt
.dxOffset
= -first
;
432 fmt
.dwMask
= PFM_RIGHTINDENT
;
433 fmt
.dxRightIndent
= info
->rtfParam
;
437 fmt
.dwMask
= PFM_ALIGNMENT
;
438 fmt
.wAlignment
= PFA_LEFT
;
441 fmt
.dwMask
= PFM_ALIGNMENT
;
442 fmt
.wAlignment
= PFA_RIGHT
;
445 fmt
.dwMask
= PFM_ALIGNMENT
;
446 fmt
.wAlignment
= PFA_CENTER
;
449 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
450 if (!(fmt
.dwMask
& PFM_TABSTOPS
))
452 fmt
.dwMask
|= PFM_TABSTOPS
;
455 if (fmt
.cTabCount
< MAX_TAB_STOPS
)
456 fmt
.rgxTabs
[fmt
.cTabCount
++] = info
->rtfParam
;
460 RTFFlushOutputBuffer(info
);
461 /* FIXME too slow ? how come ?*/
462 ME_SetSelectionParaFormat(info
->editor
, &fmt
);
466 static void ME_RTFReadHook(RTF_Info
*info
) {
467 switch(info
->rtfClass
)
470 switch(info
->rtfMajor
)
473 if (info
->stackTop
< maxStack
) {
474 memcpy(&info
->stack
[info
->stackTop
].fmt
, &info
->style
->fmt
, sizeof(CHARFORMAT2W
));
475 info
->stack
[info
->stackTop
].codePage
= info
->codePage
;
476 info
->stack
[info
->stackTop
].unicodeLength
= info
->unicodeLength
;
483 RTFFlushOutputBuffer(info
);
485 /* FIXME too slow ? how come ? */
486 s
= ME_ApplyStyle(info
->style
, &info
->stack
[info
->stackTop
].fmt
);
487 ME_ReleaseStyle(info
->style
);
489 info
->codePage
= info
->stack
[info
->stackTop
].codePage
;
490 info
->unicodeLength
= info
->stack
[info
->stackTop
].unicodeLength
;
496 switch(info
->rtfMajor
)
499 ME_RTFCharAttrHook(info
);
502 ME_RTFParAttrHook(info
);
510 ME_StreamInFill(ME_InStream
*stream
)
512 stream
->editstream
->dwError
= stream
->editstream
->pfnCallback(stream
->editstream
->dwCookie
,
514 sizeof(stream
->buffer
),
519 static LRESULT
ME_StreamIn(ME_TextEditor
*editor
, DWORD format
, EDITSTREAM
*stream
)
523 int from
, to
, to2
, nUndoMode
;
525 int nEventMask
= editor
->nEventMask
;
526 ME_InStream inStream
;
528 TRACE("stream==%p hWnd==%p format==0x%X\n", stream
, editor
->hWnd
, (UINT
)format
);
529 editor
->nEventMask
= 0;
531 ME_GetSelection(editor
, &from
, &to
);
532 if (format
& SFF_SELECTION
) {
533 style
= ME_GetSelectionInsertStyle(editor
);
535 ME_InternalDeleteText(editor
, from
, to
-from
);
538 style
= editor
->pBuffer
->pDefaultStyle
;
539 ME_AddRefStyle(style
);
540 SendMessageA(editor
->hWnd
, EM_SETSEL
, 0, 0);
541 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
));
543 ME_ClearTempStyle(editor
);
544 /* FIXME restore default paragraph formatting ! */
547 nUndoMode
= editor
->nUndoMode
;
548 editor
->nUndoMode
= umIgnore
;
550 inStream
.editstream
= stream
;
551 inStream
.editstream
->dwError
= 0;
557 /* Check if it's really RTF, and if it is not, use plain text */
558 ME_StreamInFill(&inStream
);
559 if (!inStream
.editstream
->dwError
)
561 if (strncmp(inStream
.buffer
, "{\\rtf1", 6) && strncmp(inStream
.buffer
, "{\\urtf", 6))
569 if (!inStream
.editstream
->dwError
)
571 if (format
& SF_RTF
) {
572 /* setup the RTF parser */
573 memset(&parser
, 0, sizeof parser
);
574 RTFSetEditStream(&parser
, &inStream
);
575 parser
.rtfFormat
= format
&(SF_TEXT
|SF_RTF
);
576 parser
.hwndEdit
= editor
->hWnd
;
577 parser
.editor
= editor
;
578 parser
.style
= style
;
581 RTFSetReadHook(&parser
, ME_RTFReadHook
);
586 RTFFlushOutputBuffer(&parser
);
589 style
= parser
.style
;
591 else if (format
& SF_TEXT
)
592 ME_StreamInText(editor
, format
, &inStream
, style
);
594 ERR("EM_STREAMIN without SF_TEXT or SF_RTF\n");
595 ME_GetSelection(editor
, &to
, &to2
);
596 /* put the cursor at the top */
597 if (!(format
& SFF_SELECTION
))
598 SendMessageA(editor
->hWnd
, EM_SETSEL
, 0, 0);
601 /* FIXME where to put cursor now ? */
605 editor
->nUndoMode
= nUndoMode
;
606 pUI
= ME_AddUndoItem(editor
, diUndoDeleteRun
, NULL
);
607 TRACE("from %d to %d\n", from
, to
);
608 if (pUI
&& from
< to
)
613 ME_CommitUndo(editor
);
614 ME_ReleaseStyle(style
);
615 editor
->nEventMask
= nEventMask
;
616 InvalidateRect(editor
->hWnd
, NULL
, TRUE
);
617 ME_UpdateRepaint(editor
);
618 if (!(format
& SFF_SELECTION
)) {
619 ME_ClearTempStyle(editor
);
621 ME_MoveCaret(editor
);
622 ME_SendSelChange(editor
);
629 ME_FindItemAtOffset(ME_TextEditor
*editor
, ME_DIType nItemType
, int nOffset
, int *nItemOffset
)
631 ME_DisplayItem
*item
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
633 while (item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= nOffset
)
634 item
= ME_FindItemFwd(item
, diParagraph
);
639 nOffset
-= item
->member
.para
.nCharOfs
;
640 if (nItemType
== diParagraph
) {
642 *nItemOffset
= nOffset
;
647 item
= ME_FindItemFwd(item
, diRun
);
648 } while (item
&& (item
->member
.run
.nCharOfs
+ ME_StrLen(item
->member
.run
.strText
) <= nOffset
));
650 nOffset
-= item
->member
.run
.nCharOfs
;
652 *nItemOffset
= nOffset
;
659 ME_FindText(ME_TextEditor
*editor
, DWORD flags
, CHARRANGE
*chrg
, WCHAR
*text
, CHARRANGE
*chrgText
)
661 int nStart
= chrg
->cpMin
;
662 int nLen
= lstrlenW(text
);
663 ME_DisplayItem
*item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
664 ME_DisplayItem
*para
;
672 chrgText
->cpMin
= chrgText
->cpMax
= chrg
->cpMin
;
676 if (!(flags
& FR_DOWN
))
677 FIXME("Backward search not implemented\n");
678 if (!(flags
& FR_MATCHCASE
))
679 FIXME("Case-insensitive search not implemented\n");
680 if (flags
& ~(FR_DOWN
| FR_MATCHCASE
))
681 FIXME("Flags 0x%08lx not implemented\n", flags
& ~(FR_DOWN
| FR_MATCHCASE
));
683 para
= ME_GetParagraph(item
);
684 while (item
&& para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
+ nLen
< chrg
->cpMax
)
686 ME_DisplayItem
*pCurItem
= item
;
687 int nCurStart
= nStart
;
690 while (pCurItem
->member
.run
.strText
->szData
[nCurStart
+ nMatched
] == text
[nMatched
])
693 if (nMatched
== nLen
)
695 nStart
+= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
;
698 chrgText
->cpMin
= nStart
;
699 chrgText
->cpMax
= nStart
+ nLen
;
703 if (nCurStart
+ nMatched
== ME_StrLen(pCurItem
->member
.run
.strText
))
705 pCurItem
= ME_FindItemFwd(pCurItem
, diRun
);
706 nCurStart
= -nMatched
;
710 if (nStart
== ME_StrLen(item
->member
.run
.strText
))
712 item
= ME_FindItemFwd(item
, diRun
);
713 para
= ME_GetParagraph(item
);
721 ME_TextEditor
*ME_MakeEditor(HWND hWnd
) {
722 ME_TextEditor
*ed
= ALLOC_OBJ(ME_TextEditor
);
726 ed
->bEmulateVersion10
= FALSE
;
727 ed
->pBuffer
= ME_MakeText();
729 ME_MakeFirstParagraph(hDC
, ed
->pBuffer
);
730 ReleaseDC(hWnd
, hDC
);
731 ed
->bCaretShown
= FALSE
;
733 ed
->pCursors
= ALLOC_N_OBJ(ME_Cursor
, ed
->nCursors
);
734 ed
->pCursors
[0].pRun
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diRun
);
735 ed
->pCursors
[0].nOffset
= 0;
736 ed
->pCursors
[1].pRun
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diRun
);
737 ed
->pCursors
[1].nOffset
= 0;
738 ed
->nLastTotalLength
= ed
->nTotalLength
= 0;
741 ed
->rgbBackColor
= -1;
742 ed
->bCaretAtEnd
= FALSE
;
745 ed
->pUndoStack
= ed
->pRedoStack
= NULL
;
746 ed
->nUndoMode
= umAddToUndo
;
748 ed
->nLastSelStart
= ed
->nLastSelEnd
= 0;
750 ed
->nZoomNumerator
= ed
->nZoomDenominator
= 0;
751 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
753 ed
->pFontCache
[i
].nRefs
= 0;
754 ed
->pFontCache
[i
].nAge
= 0;
755 ed
->pFontCache
[i
].hFont
= NULL
;
757 ME_CheckCharOffsets(ed
);
761 typedef struct tagME_GlobalDestStruct
765 } ME_GlobalDestStruct
;
767 static DWORD CALLBACK
ME_AppendToHGLOBAL(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
769 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
773 nMaxSize
= GlobalSize(pData
->hData
);
774 if (pData
->nLength
+cb
+1 >= cb
)
776 /* round up to 2^17 */
777 int nNewSize
= (((nMaxSize
+cb
+1)|0x1FFFF)+1) & 0xFFFE0000;
778 pData
->hData
= GlobalReAlloc(pData
->hData
, nNewSize
, 0);
780 pDest
= (BYTE
*)GlobalLock(pData
->hData
);
781 memcpy(pDest
+ pData
->nLength
, lpBuff
, cb
);
782 pData
->nLength
+= cb
;
783 pDest
[pData
->nLength
] = '\0';
784 GlobalUnlock(pData
->hData
);
790 static DWORD CALLBACK
ME_ReadFromHGLOBALUnicode(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
792 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
797 pDest
= (WORD
*)lpBuff
;
798 pSrc
= (WORD
*)GlobalLock(pData
->hData
);
799 for (i
= 0; i
<cb
&& pSrc
[pData
->nLength
+i
]; i
++) {
800 pDest
[i
] = pSrc
[pData
->nLength
+i
];
804 GlobalUnlock(pData
->hData
);
808 static DWORD CALLBACK
ME_ReadFromHGLOBALRTF(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
810 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
815 pSrc
= (BYTE
*)GlobalLock(pData
->hData
);
816 for (i
= 0; i
<cb
&& pSrc
[pData
->nLength
+i
]; i
++) {
817 pDest
[i
] = pSrc
[pData
->nLength
+i
];
821 GlobalUnlock(pData
->hData
);
826 void ME_DestroyEditor(ME_TextEditor
*editor
)
828 ME_DisplayItem
*pFirst
= editor
->pBuffer
->pFirst
;
829 ME_DisplayItem
*p
= pFirst
, *pNext
= NULL
;
832 ME_ClearTempStyle(editor
);
833 ME_EmptyUndoStack(editor
);
836 ME_DestroyDisplayItem(p
);
839 ME_ReleaseStyle(editor
->pBuffer
->pDefaultStyle
);
840 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
842 if (editor
->pFontCache
[i
].hFont
)
843 DeleteObject(editor
->pFontCache
[i
].hFont
);
849 static WCHAR wszClassName
[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '2', '0', 'W', 0};
850 static WCHAR wszClassName50
[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '5', '0', 'W', 0};
852 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
857 case DLL_PROCESS_ATTACH
:
858 DisableThreadLibraryCalls(hinstDLL
);
859 me_heap
= HeapCreate (0, 0x10000, 0);
860 ME_RegisterEditorClass(hinstDLL
);
863 case DLL_PROCESS_DETACH
:
864 UnregisterClassW(wszClassName
, 0);
865 UnregisterClassW(wszClassName50
, 0);
866 UnregisterClassA("RichEdit20A", 0);
867 UnregisterClassA("RichEdit50A", 0);
868 HeapDestroy (me_heap
);
876 #define UNSUPPORTED_MSG(e) \
878 FIXME(#e ": stub\n"); \
879 return DefWindowProcW(hWnd, msg, wParam, lParam);
881 static const char * const edit_messages
[] = {
910 "EM_SETPASSWORDCHAR",
911 "EM_EMPTYUNDOBUFFER",
912 "EM_GETFIRSTVISIBLELINE",
914 "EM_SETWORDBREAKPROC",
915 "EM_GETWORDBREAKPROC",
916 "EM_GETPASSWORDCHAR",
924 static const char * const richedit_messages
[] = {
935 "EM_GETOLEINTERFACE",
947 "EM_SETTARGETDEVICE",
955 "EM_GETWORDBREAKPROCEX",
956 "EM_SETWORDBREAKPROCEX",
958 "EM_UNKNOWN_USER_83",
963 "EM_STOPGROUPTYPING",
967 "EM_GETAUTOURLDETECT",
970 "EM_GETTEXTLENGTHEX",
973 "EM_UNKNOWN_USER_98",
974 "EM_UNKNOWN_USER_99",
977 "EM_SETWORDWRAPMODE",
978 "EM_GETWORDWRAPMODE",
984 "EM_UNKNOWN_USER_109",
985 "EM_UNKNOWN_USER_110",
986 "EM_UNKNOWN_USER_111",
987 "EM_UNKNOWN_USER_112",
988 "EM_UNKNOWN_USER_113",
989 "EM_UNKNOWN_USER_114",
990 "EM_UNKNOWN_USER_115",
991 "EM_UNKNOWN_USER_116",
992 "EM_UNKNOWN_USER_117",
993 "EM_UNKNOWN_USER_118",
994 "EM_UNKNOWN_USER_119",
1001 "EM_SETIMEMODEBIAS",
1006 get_msg_name(UINT msg
)
1008 if (msg
>= EM_GETSEL
&& msg
<= EM_SETLIMITTEXT
)
1009 return edit_messages
[msg
- EM_GETSEL
];
1010 if (msg
>= EM_CANPASTE
&& msg
<= EM_GETIMEMODEBIAS
)
1011 return richedit_messages
[msg
- EM_CANPASTE
];
1015 /******************************************************************
1016 * RichEditANSIWndProc (RICHED20.10)
1018 LRESULT WINAPI
RichEditANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
) {
1022 ME_TextEditor
*editor
= (ME_TextEditor
*)GetWindowLongW(hWnd
, 0);
1024 TRACE("msg %d (%s) %08x %08lx\n", msg
, get_msg_name(msg
), wParam
, lParam
);
1028 UNSUPPORTED_MSG(EM_AUTOURLDETECT
)
1029 UNSUPPORTED_MSG(EM_CHARFROMPOS
)
1030 UNSUPPORTED_MSG(EM_DISPLAYBAND
)
1031 UNSUPPORTED_MSG(EM_EXLIMITTEXT
)
1032 UNSUPPORTED_MSG(EM_FINDWORDBREAK
)
1033 UNSUPPORTED_MSG(EM_FMTLINES
)
1034 UNSUPPORTED_MSG(EM_FORMATRANGE
)
1035 UNSUPPORTED_MSG(EM_GETAUTOURLDETECT
)
1036 UNSUPPORTED_MSG(EM_GETBIDIOPTIONS
)
1037 UNSUPPORTED_MSG(EM_GETEDITSTYLE
)
1038 UNSUPPORTED_MSG(EM_GETFIRSTVISIBLELINE
)
1039 UNSUPPORTED_MSG(EM_GETIMECOMPMODE
)
1040 /* UNSUPPORTED_MSG(EM_GETIMESTATUS) missing in Wine headers */
1041 UNSUPPORTED_MSG(EM_GETLANGOPTIONS
)
1042 UNSUPPORTED_MSG(EM_GETLIMITTEXT
)
1043 UNSUPPORTED_MSG(EM_GETLINE
)
1044 /* UNSUPPORTED_MSG(EM_GETOLEINTERFACE) separate stub */
1045 UNSUPPORTED_MSG(EM_GETOPTIONS
)
1046 UNSUPPORTED_MSG(EM_GETPASSWORDCHAR
)
1047 UNSUPPORTED_MSG(EM_GETRECT
)
1048 UNSUPPORTED_MSG(EM_GETREDONAME
)
1049 UNSUPPORTED_MSG(EM_GETSCROLLPOS
)
1050 UNSUPPORTED_MSG(EM_GETTEXTMODE
)
1051 UNSUPPORTED_MSG(EM_GETTYPOGRAPHYOPTIONS
)
1052 UNSUPPORTED_MSG(EM_GETUNDONAME
)
1053 UNSUPPORTED_MSG(EM_GETWORDBREAKPROC
)
1054 UNSUPPORTED_MSG(EM_GETWORDBREAKPROCEX
)
1055 UNSUPPORTED_MSG(EM_HIDESELECTION
)
1056 UNSUPPORTED_MSG(EM_LIMITTEXT
) /* also known as EM_SETLIMITTEXT */
1057 UNSUPPORTED_MSG(EM_PASTESPECIAL
)
1058 /* UNSUPPORTED_MSG(EM_POSFROMCHARS) missing in Wine headers */
1059 UNSUPPORTED_MSG(EM_REQUESTRESIZE
)
1060 UNSUPPORTED_MSG(EM_SCROLL
)
1061 UNSUPPORTED_MSG(EM_SCROLLCARET
)
1062 UNSUPPORTED_MSG(EM_SELECTIONTYPE
)
1063 UNSUPPORTED_MSG(EM_SETBIDIOPTIONS
)
1064 UNSUPPORTED_MSG(EM_SETEDITSTYLE
)
1065 UNSUPPORTED_MSG(EM_SETFONTSIZE
)
1066 UNSUPPORTED_MSG(EM_SETLANGOPTIONS
)
1067 UNSUPPORTED_MSG(EM_SETOLECALLBACK
)
1068 UNSUPPORTED_MSG(EM_SETOPTIONS
)
1069 UNSUPPORTED_MSG(EM_SETPALETTE
)
1070 UNSUPPORTED_MSG(EM_SETPASSWORDCHAR
)
1071 UNSUPPORTED_MSG(EM_SETRECT
)
1072 UNSUPPORTED_MSG(EM_SETRECTNP
)
1073 UNSUPPORTED_MSG(EM_SETSCROLLPOS
)
1074 UNSUPPORTED_MSG(EM_SETTABSTOPS
)
1075 UNSUPPORTED_MSG(EM_SETTARGETDEVICE
)
1076 UNSUPPORTED_MSG(EM_SETTEXTMODE
)
1077 UNSUPPORTED_MSG(EM_SETTYPOGRAPHYOPTIONS
)
1078 UNSUPPORTED_MSG(EM_SETUNDOLIMIT
)
1079 UNSUPPORTED_MSG(EM_SETWORDBREAKPROC
)
1080 UNSUPPORTED_MSG(EM_SETWORDBREAKPROCEX
)
1081 UNSUPPORTED_MSG(EM_SHOWSCROLLBAR
)
1082 UNSUPPORTED_MSG(WM_SETFONT
)
1083 UNSUPPORTED_MSG(WM_STYLECHANGING
)
1084 UNSUPPORTED_MSG(WM_STYLECHANGED
)
1085 /* UNSUPPORTED_MSG(WM_UNICHAR) FIXME missing in Wine headers */
1087 /* Messages specific to Richedit controls */
1090 return ME_StreamIn(editor
, wParam
, (EDITSTREAM
*)lParam
);
1092 return ME_StreamOut(editor
, wParam
, (EDITSTREAM
*)lParam
);
1095 UINT code
= DLGC_WANTCHARS
|DLGC_WANTARROWS
;
1096 if (GetWindowLongW(hWnd
, GWL_STYLE
)&ES_WANTRETURN
)
1097 code
|= 0; /* FIXME what can we do here ? ask for messages and censor them ? */
1102 CREATESTRUCTW
*pcs
= (CREATESTRUCTW
*)lParam
;
1103 TRACE("WM_NCCREATE: style 0x%08lx\n", pcs
->style
);
1104 editor
= ME_MakeEditor(hWnd
);
1105 SetWindowLongW(hWnd
, 0, (long)editor
);
1106 pcs
= 0; /* ignore */
1109 case EM_EMPTYUNDOBUFFER
:
1110 ME_EmptyUndoStack(editor
);
1114 /* Note: wParam/lParam can be NULL */
1116 PUINT pfrom
= wParam
? (PUINT
)wParam
: &from
;
1117 PUINT pto
= lParam
? (PUINT
)lParam
: &to
;
1118 ME_GetSelection(editor
, pfrom
, pto
);
1119 if ((*pfrom
|*pto
) & 0xFFFF0000)
1121 return MAKELONG(*pfrom
,*pto
);
1125 CHARRANGE
*pRange
= (CHARRANGE
*)lParam
;
1126 ME_GetSelection(editor
, (int *)&pRange
->cpMin
, (int *)&pRange
->cpMax
);
1127 TRACE("EM_EXGETSEL = (%ld,%ld)\n", pRange
->cpMin
, pRange
->cpMax
);
1131 return editor
->pUndoStack
!= NULL
;
1133 return editor
->pRedoStack
!= NULL
;
1142 ME_SetSelection(editor
, wParam
, lParam
);
1144 ME_SendSelChange(editor
);
1149 CHARRANGE
*pRange
= (CHARRANGE
*)lParam
;
1150 TRACE("EM_EXSETSEL (%ld,%ld)\n", pRange
->cpMin
, pRange
->cpMax
);
1151 ME_SetSelection(editor
, pRange
->cpMin
, pRange
->cpMax
);
1152 /* FIXME optimize */
1154 ME_SendSelChange(editor
);
1159 LPWSTR wszText
= (LPWSTR
)lParam
;
1160 SETTEXTEX
*pStruct
= (SETTEXTEX
*)wParam
;
1161 size_t len
= lstrlenW(wszText
);
1164 TRACE("EM_SETTEXEX - %s, flags %d, cp %d\n", debugstr_w(wszText
), (int)pStruct
->flags
, pStruct
->codepage
);
1165 if (pStruct
->codepage
!= 1200) {
1166 FIXME("EM_SETTEXTEX only supports unicode right now!\n");
1169 /* FIXME: this should support RTF strings too, according to MSDN */
1170 if (pStruct
->flags
& ST_SELECTION
) {
1171 ME_GetSelection(editor
, &from
, &to
);
1172 style
= ME_GetSelectionInsertStyle(editor
);
1173 ME_InternalDeleteText(editor
, from
, to
- from
);
1174 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, style
);
1175 ME_ReleaseStyle(style
);
1178 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
));
1179 ME_InsertTextFromCursor(editor
, 0, wszText
, -1, editor
->pBuffer
->pDefaultStyle
);
1182 ME_CommitUndo(editor
);
1183 if (!(pStruct
->flags
& ST_KEEPUNDO
))
1184 ME_EmptyUndoStack(editor
);
1185 ME_UpdateRepaint(editor
);
1188 case EM_SETBKGNDCOLOR
:
1190 LRESULT lColor
= ME_GetBackColor(editor
);
1192 editor
->rgbBackColor
= -1;
1194 editor
->rgbBackColor
= lParam
;
1195 InvalidateRect(hWnd
, NULL
, TRUE
);
1200 return editor
->nModifyStep
== 0 ? 0 : 1;
1204 editor
->nModifyStep
= 0x80000000;
1206 editor
->nModifyStep
= 0;
1210 case EM_SETREADONLY
:
1212 long nStyle
= GetWindowLongW(hWnd
, GWL_STYLE
);
1214 nStyle
|= ES_READONLY
;
1216 nStyle
&= ~ES_READONLY
;
1217 SetWindowLongW(hWnd
, GWL_STYLE
, nStyle
);
1221 case EM_SETEVENTMASK
:
1222 editor
->nEventMask
= lParam
;
1224 case EM_GETEVENTMASK
:
1225 return editor
->nEventMask
;
1226 case EM_SETCHARFORMAT
:
1228 CHARFORMAT2W buf
, *p
;
1229 BOOL bRepaint
= TRUE
;
1230 p
= ME_ToCF2W(&buf
, (CHARFORMAT2W
*)lParam
);
1232 ME_SetDefaultCharFormat(editor
, p
);
1233 else if (wParam
== (SCF_WORD
| SCF_SELECTION
))
1234 FIXME("EM_SETCHARFORMAT: word selection not supported\n");
1235 else if (wParam
== SCF_ALL
)
1236 ME_SetCharFormat(editor
, 0, ME_GetTextLength(editor
), p
);
1239 ME_GetSelection(editor
, &from
, &to
);
1240 bRepaint
= (from
!= to
);
1241 ME_SetSelectionCharFormat(editor
, p
);
1243 ME_CommitUndo(editor
);
1245 ME_UpdateRepaint(editor
);
1248 case EM_GETCHARFORMAT
:
1250 CHARFORMAT2W tmp
, *dst
= (CHARFORMAT2W
*)lParam
;
1251 if (dst
->cbSize
!= sizeof(CHARFORMATA
) &&
1252 dst
->cbSize
!= sizeof(CHARFORMATW
) &&
1253 dst
->cbSize
!= sizeof(CHARFORMAT2A
) &&
1254 dst
->cbSize
!= sizeof(CHARFORMAT2W
))
1256 tmp
.cbSize
= sizeof(tmp
);
1258 ME_GetDefaultCharFormat(editor
, &tmp
);
1260 ME_GetSelectionCharFormat(editor
, &tmp
);
1261 ME_CopyToCFAny(dst
, &tmp
);
1264 case EM_SETPARAFORMAT
:
1265 ME_SetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
1266 ME_UpdateRepaint(editor
);
1267 ME_CommitUndo(editor
);
1269 case EM_GETPARAFORMAT
:
1270 ME_GetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
1274 int nPos
= editor
->nScrollPosY
, nEnd
= editor
->nTotalLength
- editor
->sizeWindow
.cy
;
1275 nPos
+= 8 * lParam
; /* FIXME follow the original */
1280 if (nPos
!= editor
->nScrollPosY
) {
1281 ScrollWindow(hWnd
, 0, editor
->nScrollPosY
-nPos
, NULL
, NULL
);
1282 editor
->nScrollPosY
= nPos
;
1283 SetScrollPos(hWnd
, SB_VERT
, nPos
, TRUE
);
1286 return TRUE
; /* Should return false if a single line richedit control */
1291 ME_GetSelection(editor
, &from
, &to
);
1292 ME_InternalDeleteText(editor
, from
, to
-from
);
1293 ME_CommitUndo(editor
);
1294 ME_UpdateRepaint(editor
);
1301 LPWSTR wszText
= ME_ToUnicode(hWnd
, (void *)lParam
);
1302 size_t len
= lstrlenW(wszText
);
1303 TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText
));
1305 ME_GetSelection(editor
, &from
, &to
);
1306 style
= ME_GetSelectionInsertStyle(editor
);
1307 ME_InternalDeleteText(editor
, from
, to
-from
);
1308 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, style
);
1309 ME_ReleaseStyle(style
);
1310 ME_EndToUnicode(hWnd
, wszText
);
1311 /* drop temporary style if line end */
1312 /* FIXME question: does abc\n mean: put abc, clear temp style, put \n? (would require a change) */
1313 if (len
>0 && wszText
[len
-1] == '\n')
1314 ME_ClearTempStyle(editor
);
1316 ME_CommitUndo(editor
);
1318 ME_EmptyUndoStack(editor
);
1319 ME_UpdateRepaint(editor
);
1324 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
));
1327 LPWSTR wszText
= ME_ToUnicode(hWnd
, (void *)lParam
);
1328 TRACE("WM_SETTEXT lParam==%lx\n",lParam
);
1329 TRACE("WM_SETTEXT - %s\n", debugstr_w(wszText
)); /* debugstr_w() */
1330 if (lstrlenW(wszText
) > 0)
1332 /* uses default style! */
1333 ME_InsertTextFromCursor(editor
, 0, wszText
, -1, editor
->pBuffer
->pDefaultStyle
);
1335 ME_EndToUnicode(hWnd
, wszText
);
1338 TRACE("WM_SETTEXT - NULL\n");
1339 ME_CommitUndo(editor
);
1340 ME_EmptyUndoStack(editor
);
1341 ME_UpdateRepaint(editor
);
1346 UINT nRTFFormat
= RegisterClipboardFormatA("Rich Text Format");
1347 if (IsClipboardFormatAvailable(nRTFFormat
))
1349 if (IsClipboardFormatAvailable(CF_UNICODETEXT
))
1357 ME_GlobalDestStruct gds
;
1358 UINT nRTFFormat
= RegisterClipboardFormatA("Rich Text Format");
1361 if (IsClipboardFormatAvailable(nRTFFormat
))
1362 cf
= nRTFFormat
, dwFormat
= SF_RTF
;
1363 else if (IsClipboardFormatAvailable(CF_UNICODETEXT
))
1364 cf
= CF_UNICODETEXT
, dwFormat
= SF_TEXT
|SF_UNICODE
;
1368 if (!OpenClipboard(hWnd
))
1370 gds
.hData
= GetClipboardData(cf
);
1372 es
.dwCookie
= (DWORD
)&gds
;
1373 es
.pfnCallback
= dwFormat
== SF_RTF
? ME_ReadFromHGLOBALRTF
: ME_ReadFromHGLOBALUnicode
;
1374 SendMessageW(hWnd
, EM_STREAMIN
, dwFormat
|SFF_SELECTION
, (LPARAM
)&es
);
1386 ME_GlobalDestStruct gds
;
1388 if (!OpenClipboard(hWnd
))
1392 ME_GetSelection(editor
, &from
, &to
);
1393 pars
= ME_CountParagraphsBetween(editor
, from
, to
);
1394 hData
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(WCHAR
)*(to
-from
+pars
+1));
1395 data
= (WCHAR
*)GlobalLock(hData
);
1396 ME_GetTextW(editor
, data
, from
, to
-from
, TRUE
);
1397 GlobalUnlock(hData
);
1399 gds
.hData
= GlobalAlloc(GMEM_MOVEABLE
, 0);
1401 es
.dwCookie
= (DWORD
)&gds
;
1402 es
.pfnCallback
= ME_AppendToHGLOBAL
;
1403 SendMessageW(hWnd
, EM_STREAMOUT
, SFF_SELECTION
|SF_RTF
, (LPARAM
)&es
);
1404 GlobalReAlloc(gds
.hData
, gds
.nLength
+1, 0);
1406 SetClipboardData(CF_UNICODETEXT
, hData
);
1407 SetClipboardData(RegisterClipboardFormatA("Rich Text Format"), gds
.hData
);
1412 ME_InternalDeleteText(editor
, from
, to
-from
);
1413 ME_CommitUndo(editor
);
1414 ME_UpdateRepaint(editor
);
1418 case WM_GETTEXTLENGTH
:
1419 return ME_GetTextLength(editor
);
1420 case EM_GETTEXTLENGTHEX
:
1421 return ME_GetTextLengthEx(editor
, (GETTEXTLENGTHEX
*)wParam
);
1424 TEXTRANGEW tr
; /* W and A differ only by rng->lpstrText */
1426 tr
.chrg
.cpMax
= wParam
-1;
1427 tr
.lpstrText
= (WCHAR
*)lParam
;
1428 return RichEditANSIWndProc(hWnd
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
);
1432 GETTEXTEX
*ex
= (GETTEXTEX
*)wParam
;
1435 FIXME("Unhandled EM_GETTEXTEX flags 0x%lx\n",ex
->flags
);
1437 if (IsWindowUnicode(hWnd
))
1438 return ME_GetTextW(editor
, (LPWSTR
)lParam
, 0, ex
->cb
, FALSE
);
1441 LPWSTR buffer
= HeapAlloc(GetProcessHeap(),0,ex
->cb
*sizeof(WCHAR
));
1442 DWORD buflen
= ex
->cb
;
1446 buflen
= ME_GetTextW(editor
, buffer
, 0, buflen
, FALSE
);
1447 rc
= WideCharToMultiByte(ex
->codepage
, flags
, buffer
, buflen
, (LPSTR
)lParam
, ex
->cb
, ex
->lpDefaultChar
, ex
->lpUsedDefaultChar
);
1449 HeapFree(GetProcessHeap(),0,buffer
);
1456 TEXTRANGEW tr
; /* W and A differ only by rng->lpstrText */
1457 ME_GetSelection(editor
, &from
, &to
);
1458 tr
.chrg
.cpMin
= from
;
1460 tr
.lpstrText
= (WCHAR
*)lParam
;
1461 return RichEditANSIWndProc(hWnd
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
);
1463 case EM_GETTEXTRANGE
:
1465 TEXTRANGEW
*rng
= (TEXTRANGEW
*)lParam
;
1466 if (IsWindowUnicode(hWnd
))
1467 return ME_GetTextW(editor
, rng
->lpstrText
, rng
->chrg
.cpMin
, rng
->chrg
.cpMax
-rng
->chrg
.cpMin
, FALSE
);
1470 int nLen
= rng
->chrg
.cpMax
-rng
->chrg
.cpMin
;
1471 WCHAR
*p
= ALLOC_N_OBJ(WCHAR
, nLen
+1);
1472 int nChars
= ME_GetTextW(editor
, p
, rng
->chrg
.cpMin
, nLen
, FALSE
);
1473 /* FIXME this is a potential security hole (buffer overrun)
1474 if you know more about wchar->mbyte conversion please explain
1476 WideCharToMultiByte(CP_ACP
, 0, p
, nChars
+1, (char *)rng
->lpstrText
, nLen
+1, NULL
, NULL
);
1480 return ME_GetTextW(editor
, rng
->lpstrText
, rng
->chrg
.cpMin
, rng
->chrg
.cpMax
-rng
->chrg
.cpMin
, FALSE
);
1482 case EM_GETLINECOUNT
:
1484 ME_DisplayItem
*item
= editor
->pBuffer
->pFirst
->next
;
1487 while (item
!= editor
->pBuffer
->pLast
)
1489 assert(item
->type
== diParagraph
);
1490 nRows
+= item
->member
.para
.nRows
;
1491 item
= item
->member
.para
.next_para
;
1493 TRACE("EM_GETLINECOUNT: nRows==%d\n", nRows
);
1494 return max(1, nRows
);
1496 case EM_LINEFROMCHAR
:
1499 return ME_RowNumberFromCharOfs(editor
, ME_GetCursorOfs(editor
, 1));
1501 return ME_RowNumberFromCharOfs(editor
, wParam
);
1503 case EM_EXLINEFROMCHAR
:
1505 return ME_RowNumberFromCharOfs(editor
, lParam
);
1509 ME_DisplayItem
*item
, *para
;
1513 item
= ME_FindItemBack(editor
->pCursors
[0].pRun
, diStartRow
);
1515 item
= ME_FindRowWithNumber(editor
, wParam
);
1518 para
= ME_GetParagraph(item
);
1519 item
= ME_FindItemFwd(item
, diRun
);
1520 nCharOfs
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
;
1521 TRACE("EM_LINEINDEX: nCharOfs==%d\n", nCharOfs
);
1526 ME_DisplayItem
*item
, *item_end
;
1529 if (wParam
> ME_GetTextLength(editor
))
1533 FIXME("EM_LINELENGTH: returning number of unselected characters on lines with selection unsupported.\n");
1536 item
= ME_FindItemAtOffset(editor
, diRun
, wParam
, NULL
);
1537 item
= ME_RowStart(item
);
1538 item_end
= ME_RowEnd(item
);
1541 /* Empty buffer, no runs */
1546 nChars
= ME_CharOfsFromRunOfs(editor
, item_end
, ME_StrLen(item_end
->member
.run
.strText
));
1547 nChars
-= ME_CharOfsFromRunOfs(editor
, item
, 0);
1549 TRACE("EM_LINELENGTH(%d)==%d\n",wParam
, nChars
);
1554 FINDTEXTA
*ft
= (FINDTEXTA
*)lParam
;
1555 int nChars
= MultiByteToWideChar(CP_ACP
, 0, ft
->lpstrText
, -1, NULL
, 0);
1558 if ((tmp
= ALLOC_N_OBJ(WCHAR
, nChars
)) != NULL
)
1559 MultiByteToWideChar(CP_ACP
, 0, ft
->lpstrText
, -1, tmp
, nChars
);
1560 return ME_FindText(editor
, wParam
, &ft
->chrg
, tmp
, NULL
);
1564 FINDTEXTEXA
*ex
= (FINDTEXTEXA
*)lParam
;
1565 int nChars
= MultiByteToWideChar(CP_ACP
, 0, ex
->lpstrText
, -1, NULL
, 0);
1568 if ((tmp
= ALLOC_N_OBJ(WCHAR
, nChars
)) != NULL
)
1569 MultiByteToWideChar(CP_ACP
, 0, ex
->lpstrText
, -1, tmp
, nChars
);
1570 return ME_FindText(editor
, wParam
, &ex
->chrg
, tmp
, &ex
->chrgText
);
1574 FINDTEXTW
*ft
= (FINDTEXTW
*)lParam
;
1575 return ME_FindText(editor
, wParam
, &ft
->chrg
, ft
->lpstrText
, NULL
);
1577 case EM_FINDTEXTEXW
:
1579 FINDTEXTEXW
*ex
= (FINDTEXTEXW
*)lParam
;
1580 return ME_FindText(editor
, wParam
, &ex
->chrg
, ex
->lpstrText
, &ex
->chrgText
);
1583 if (!wParam
|| !lParam
)
1585 *(int *)wParam
= editor
->nZoomNumerator
;
1586 *(int *)lParam
= editor
->nZoomDenominator
;
1589 return ME_SetZoom(editor
, wParam
, lParam
);
1591 ME_CommitUndo(editor
);
1592 ME_WrapMarkedParagraphs(editor
);
1593 ME_MoveCaret(editor
);
1596 ME_DestroyEditor(editor
);
1597 SetWindowLongW(hWnd
, 0, 0);
1599 case WM_LBUTTONDOWN
:
1601 ME_LButtonDown(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
1605 if (GetCapture() == hWnd
)
1606 ME_MouseMove(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
1609 if (GetCapture() == hWnd
)
1613 hDC
= BeginPaint(hWnd
, &ps
);
1614 ME_PaintContent(editor
, hDC
, FALSE
, &ps
.rcPaint
);
1615 EndPaint(hWnd
, &ps
);
1618 ME_ShowCaret(editor
);
1619 ME_SendOldNotify(editor
, EN_SETFOCUS
);
1622 ME_HideCaret(editor
);
1623 ME_SendOldNotify(editor
, EN_KILLFOCUS
);
1627 HDC hDC
= (HDC
)wParam
;
1629 COLORREF rgbBG
= ME_GetBackColor(editor
);
1630 if (GetUpdateRect(hWnd
,&rc
,TRUE
))
1632 HBRUSH hbr
= CreateSolidBrush(rgbBG
);
1633 FillRect(hDC
, &rc
, hbr
);
1639 TRACE("editor wnd command = %d\n", LOWORD(wParam
));
1642 if (ME_ArrowKey(editor
, LOWORD(wParam
), GetKeyState(VK_CONTROL
)<0)) {
1643 ME_CommitUndo(editor
);
1644 ME_EnsureVisible(editor
, editor
->pCursors
[0].pRun
);
1646 ME_MoveCaret(editor
);
1650 if (GetKeyState(VK_CONTROL
)<0)
1652 if (LOWORD(wParam
)=='W')
1656 ME_GetSelectionCharFormat(editor
, &chf
);
1657 ME_DumpStyleToBuf(&chf
, buf
);
1658 MessageBoxA(NULL
, buf
, "Style dump", MB_OK
);
1660 if (LOWORD(wParam
)=='Q')
1662 ME_CheckCharOffsets(editor
);
1669 if (GetWindowLongW(editor
->hWnd
, GWL_STYLE
) & ES_READONLY
) {
1670 MessageBeep(MB_ICONERROR
);
1671 return 0; /* FIXME really 0 ? */
1673 wstr
= LOWORD(wParam
);
1674 if (((unsigned)wstr
)>=' ' || wstr
=='\r' || wstr
=='\t') {
1675 /* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */
1676 ME_Style
*style
= ME_GetInsertStyle(editor
, 0);
1677 ME_SaveTempStyle(editor
);
1678 ME_InsertTextFromCursor(editor
, 0, &wstr
, 1, style
);
1679 ME_ReleaseStyle(style
);
1680 ME_CommitUndo(editor
);
1681 ME_UpdateRepaint(editor
);
1687 int nPos
= editor
->nScrollPosY
;
1688 si
.cbSize
= sizeof(SCROLLINFO
);
1689 si
.fMask
= SIF_PAGE
|SIF_POS
|SIF_RANGE
|SIF_TRACKPOS
;
1690 GetScrollInfo(hWnd
, SB_VERT
, &si
);
1691 switch(LOWORD(wParam
)) {
1693 nPos
-= 24; /* FIXME follow the original */
1694 if (nPos
<0) nPos
= 0;
1698 int nEnd
= editor
->nTotalLength
- editor
->sizeWindow
.cy
;
1699 nPos
+= 24; /* FIXME follow the original */
1700 if (nPos
>=nEnd
) nPos
= nEnd
;
1704 nPos
-= editor
->sizeWindow
.cy
;
1705 if (nPos
<0) nPos
= 0;
1708 nPos
+= editor
->sizeWindow
.cy
;
1709 if (nPos
>=editor
->nTotalLength
) nPos
= editor
->nTotalLength
-1;
1712 case SB_THUMBPOSITION
:
1713 nPos
= si
.nTrackPos
;
1716 if (nPos
!= editor
->nScrollPosY
) {
1717 ScrollWindow(hWnd
, 0, editor
->nScrollPosY
-nPos
, NULL
, NULL
);
1718 editor
->nScrollPosY
= nPos
;
1719 SetScrollPos(hWnd
, SB_VERT
, nPos
, TRUE
);
1726 int gcWheelDelta
= 0, nPos
= editor
->nScrollPosY
, nEnd
= editor
->nTotalLength
- editor
->sizeWindow
.cy
;
1727 UINT pulScrollLines
;
1728 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
1729 gcWheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
1730 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
1731 nPos
+= pulScrollLines
* (gcWheelDelta
/ WHEEL_DELTA
) * 8; /* FIXME follow the original */
1736 if (nPos
!= editor
->nScrollPosY
) {
1737 ScrollWindow(hWnd
, 0, editor
->nScrollPosY
-nPos
, NULL
, NULL
);
1738 editor
->nScrollPosY
= nPos
;
1739 SetScrollPos(hWnd
, SB_VERT
, nPos
, TRUE
);
1746 ME_RewrapRepaint(editor
);
1747 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
1749 case EM_GETOLEINTERFACE
:
1751 LPVOID
*ppvObj
= (LPVOID
*) lParam
;
1752 FIXME("EM_GETOLEINTERFACE %p: stub\n", ppvObj
);
1753 return CreateIRichEditOle(ppvObj
);
1757 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
1763 /******************************************************************
1764 * RichEdit10ANSIWndProc (RICHED20.9)
1766 LRESULT WINAPI
RichEdit10ANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1770 /* FIXME: this is NOT the same as 2.0 version */
1771 result
= RichEditANSIWndProc(hWnd
, msg
, wParam
, lParam
);
1772 if (msg
== WM_NCCREATE
)
1774 ME_TextEditor
*editor
= (ME_TextEditor
*)GetWindowLongW(hWnd
, 0);
1776 editor
->bEmulateVersion10
= TRUE
;
1777 editor
->pBuffer
->pLast
->member
.para
.nCharOfs
= 2;
1782 void ME_SendOldNotify(ME_TextEditor
*editor
, int nCode
)
1784 HWND hWnd
= editor
->hWnd
;
1785 SendMessageA(GetParent(hWnd
), WM_COMMAND
, (nCode
<<16)|GetWindowLongW(hWnd
, GWLP_ID
), (LPARAM
)hWnd
);
1788 int ME_CountParagraphsBetween(ME_TextEditor
*editor
, int from
, int to
)
1790 ME_DisplayItem
*item
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
1793 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= from
)
1794 item
= item
->member
.para
.next_para
;
1797 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= to
) {
1798 item
= item
->member
.para
.next_para
;
1805 int ME_GetTextW(ME_TextEditor
*editor
, WCHAR
*buffer
, int nStart
, int nChars
, int bCRLF
)
1807 ME_DisplayItem
*item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
1818 int nLen
= ME_StrLen(item
->member
.run
.strText
) - nStart
;
1821 CopyMemory(buffer
, item
->member
.run
.strText
->szData
+ nStart
, sizeof(WCHAR
)*nLen
);
1828 item
= ME_FindItemFwd(item
, diRun
);
1831 while(nChars
&& item
)
1833 int nLen
= ME_StrLen(item
->member
.run
.strText
);
1837 if (item
->member
.run
.nFlags
& MERF_ENDPARA
)
1847 CopyMemory(buffer
, item
->member
.run
.strText
->szData
, sizeof(WCHAR
)*nLen
);
1857 item
= ME_FindItemFwd(item
, diRun
);
1863 void ME_RegisterEditorClass(HINSTANCE hInstance
)
1869 wcW
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
;
1870 wcW
.lpfnWndProc
= RichEditANSIWndProc
;
1873 wcW
.hInstance
= NULL
; /* hInstance would register DLL-local class */
1875 wcW
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
1876 wcW
.hbrBackground
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
1877 wcW
.lpszMenuName
= NULL
;
1878 wcW
.lpszClassName
= wszClassName
;
1879 bResult
= RegisterClassW(&wcW
);
1881 wcW
.lpszClassName
= wszClassName50
;
1882 bResult
= RegisterClassW(&wcW
);
1885 wcA
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
;
1886 wcA
.lpfnWndProc
= RichEditANSIWndProc
;
1889 wcA
.hInstance
= NULL
; /* hInstance would register DLL-local class */
1891 wcA
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
1892 wcA
.hbrBackground
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
1893 wcA
.lpszMenuName
= NULL
;
1894 wcA
.lpszClassName
= "RichEdit20A";
1895 bResult
= RegisterClassA(&wcA
);
1897 wcA
.lpszClassName
= "RichEdit50A";
1898 bResult
= RegisterClassA(&wcA
);
1901 /******************************************************************
1902 * CreateTextServices (RICHED20.4)
1904 * FIXME should be ITextHost instead of void*
1906 HRESULT WINAPI
CreateTextServices(IUnknown
*punkOuter
, void *pITextHost
,
1910 /* FIXME should support aggregation */
1912 return CLASS_E_NOAGGREGATION
;
1914 return E_FAIL
; /* E_NOTIMPL isn't allowed by MSDN */
1917 /******************************************************************
1918 * REExtendedRegisterClass (RICHED20.8)
1920 * FIXME undocumented
1922 void WINAPI
REExtendedRegisterClass(void)