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)
209 * Bugs that are probably fixed, but not so easy to verify:
210 * - EN_UPDATE/EN_CHANGE are handled very incorrectly (should be OK now)
211 * - undo for ME_JoinParagraphs doesn't store paragraph format ? (it does)
212 * - check/fix artificial EOL logic (bCursorAtEnd, hardly logical)
213 * - caret shouldn't be displayed when selection isn't empty
214 * - check refcounting in style management functions (looks perfect now, but no bugs is suspicious)
215 * - undo for setting default format (done, might be buggy)
216 * - styles might be not released properly (looks like they work like charm, but who knows?
225 #define NO_SHLWAPI_STREAM
230 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
233 HANDLE me_heap = NULL;
235 static ME_TextBuffer *ME_MakeText(void) {
237 ME_TextBuffer *buf = ALLOC_OBJ(ME_TextBuffer);
239 ME_DisplayItem *p1 = ME_MakeDI(diTextStart);
240 ME_DisplayItem *p2 = ME_MakeDI(diTextEnd);
246 p1->member.para.next_para = p2;
247 p2->member.para.prev_para = p1;
248 p2->member.para.nCharOfs = 0;
252 buf->pCharStyle = NULL;
258 static LRESULT ME_StreamInText(ME_TextEditor *editor, DWORD dwFormat, ME_InStream *stream, ME_Style *style)
260 WCHAR wszText[STREAMIN_BUFFER_SIZE+1];
263 TRACE("%08lx %p\n", dwFormat, stream);
270 ME_StreamInFill(stream);
271 if (stream->editstream->dwError)
277 if (!(dwFormat & SF_UNICODE))
279 /* FIXME? this is doomed to fail on true MBCS like UTF-8, luckily they're unlikely to be used as CP_ACP */
280 nWideChars = MultiByteToWideChar(CP_ACP, 0, stream->buffer, stream->dwSize, wszText, STREAMIN_BUFFER_SIZE);
285 nWideChars = stream->dwSize >> 1;
286 pText = (WCHAR *)stream->buffer;
289 ME_InsertTextFromCursor(editor, 0, pText, nWideChars, style);
290 if (stream->dwSize < STREAMIN_BUFFER_SIZE)
294 ME_CommitUndo(editor);
299 static void ME_RTFCharAttrHook(RTF_Info *info)
302 fmt.cbSize = sizeof(fmt);
305 switch(info->rtfMinor)
308 /* FIXME add more flags once they're implemented */
309 fmt.dwMask = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_COLOR | CFM_BACKCOLOR | CFM_SIZE | CFM_WEIGHT;
310 fmt.dwEffects = CFE_AUTOCOLOR | CFE_AUTOBACKCOLOR;
311 fmt.yHeight = 12*20; /* 12pt */
315 fmt.dwMask = CFM_BOLD;
316 fmt.dwEffects = info->rtfParam ? fmt.dwMask : 0;
319 fmt.dwMask = CFM_ITALIC;
320 fmt.dwEffects = info->rtfParam ? fmt.dwMask : 0;
323 fmt.dwMask = CFM_UNDERLINE;
324 fmt.dwEffects = info->rtfParam ? fmt.dwMask : 0;
325 fmt.bUnderlineType = CFU_CF1UNDERLINE;
328 fmt.dwMask = CFM_UNDERLINE;
332 fmt.dwMask = CFM_STRIKEOUT;
333 fmt.dwEffects = info->rtfParam ? fmt.dwMask : 0;
337 case rtfSubScrShrink:
338 case rtfSuperScrShrink:
340 fmt.dwMask = CFM_SUBSCRIPT|CFM_SUPERSCRIPT;
341 if (info->rtfMinor == rtfSubScrShrink) fmt.dwEffects = CFE_SUBSCRIPT;
342 if (info->rtfMinor == rtfSuperScrShrink) fmt.dwEffects = CFE_SUPERSCRIPT;
343 if (info->rtfMinor == rtfNoSuperSub) fmt.dwEffects = 0;
346 fmt.dwMask = CFM_BACKCOLOR;
348 if (info->rtfParam == 0)
349 fmt.dwEffects = CFE_AUTOBACKCOLOR;
350 else if (info->rtfParam != rtfNoParam)
352 RTFColor *c = RTFGetColor(info, info->rtfParam);
353 fmt.crTextColor = (c->rtfCBlue<<16)|(c->rtfCGreen<<8)|(c->rtfCRed);
357 fmt.dwMask = CFM_COLOR;
359 if (info->rtfParam == 0)
360 fmt.dwEffects = CFE_AUTOCOLOR;
361 else if (info->rtfParam != rtfNoParam)
363 RTFColor *c = RTFGetColor(info, info->rtfParam);
364 fmt.crTextColor = (c->rtfCBlue<<16)|(c->rtfCGreen<<8)|(c->rtfCRed);
368 if (info->rtfParam != rtfNoParam)
370 RTFFont *f = RTFGetFont(info, info->rtfParam);
373 MultiByteToWideChar(CP_ACP, 0, f->rtfFName, -1, fmt.szFaceName, sizeof(fmt.szFaceName)/sizeof(WCHAR));
374 fmt.szFaceName[sizeof(fmt.szFaceName)/sizeof(WCHAR)-1] = '\0';
375 fmt.bCharSet = f->rtfFCharSet;
376 fmt.dwMask = CFM_FACE | CFM_CHARSET;
381 fmt.dwMask = CFM_SIZE;
382 if (info->rtfParam != rtfNoParam)
383 fmt.yHeight = info->rtfParam*10;
388 RTFFlushOutputBuffer(info);
389 /* FIXME too slow ? how come ? */
390 style2 = ME_ApplyStyle(info->style, &fmt);
391 ME_ReleaseStyle(info->style);
392 info->style = style2;
396 /* FIXME this function doesn't get any information about context of the RTF tag, which is very bad,
397 the same tags mean different things in different contexts */
398 static void ME_RTFParAttrHook(RTF_Info *info)
401 fmt.cbSize = sizeof(fmt);
404 switch(info->rtfMinor)
406 case rtfParDef: /* I'm not 100% sure what does it do, but I guess it restores default paragraph attributes */
407 fmt.dwMask = PFM_ALIGNMENT | PFM_TABSTOPS | PFM_OFFSET | PFM_STARTINDENT;
408 fmt.wAlignment = PFA_LEFT;
410 fmt.dxOffset = fmt.dxStartIndent = 0;
413 ME_GetSelectionParaFormat(info->editor, &fmt);
414 fmt.dwMask = PFM_STARTINDENT;
415 fmt.dxStartIndent = info->rtfParam + fmt.dxOffset;
420 ME_GetSelectionParaFormat(info->editor, &fmt);
421 first = fmt.dxStartIndent;
422 left = info->rtfParam;
423 fmt.dwMask = PFM_STARTINDENT|PFM_OFFSET;
424 fmt.dxStartIndent = first + left;
425 fmt.dxOffset = -first;
429 fmt.dwMask = PFM_RIGHTINDENT;
430 fmt.dxRightIndent = info->rtfParam;
434 fmt.dwMask = PFM_ALIGNMENT;
435 fmt.wAlignment = PFA_LEFT;
438 fmt.dwMask = PFM_ALIGNMENT;
439 fmt.wAlignment = PFA_RIGHT;
442 fmt.dwMask = PFM_ALIGNMENT;
443 fmt.wAlignment = PFA_CENTER;
446 ME_GetSelectionParaFormat(info->editor, &fmt);
447 if (!(fmt.dwMask & PFM_TABSTOPS))
449 fmt.dwMask |= PFM_TABSTOPS;
452 if (fmt.cTabCount < MAX_TAB_STOPS)
453 fmt.rgxTabs[fmt.cTabCount++] = info->rtfParam;
457 RTFFlushOutputBuffer(info);
458 /* FIXME too slow ? how come ?*/
459 ME_SetSelectionParaFormat(info->editor, &fmt);
463 static void ME_RTFReadHook(RTF_Info *info) {
464 switch(info->rtfClass)
467 switch(info->rtfMajor)
470 if (info->stackTop < maxStack) {
471 memcpy(&info->stack[info->stackTop].fmt, &info->style->fmt, sizeof(CHARFORMAT2W));
472 info->stack[info->stackTop].codePage = info->codePage;
473 info->stack[info->stackTop].unicodeLength = info->unicodeLength;
480 RTFFlushOutputBuffer(info);
482 /* FIXME too slow ? how come ? */
483 s = ME_ApplyStyle(info->style, &info->stack[info->stackTop].fmt);
484 ME_ReleaseStyle(info->style);
486 info->codePage = info->stack[info->stackTop].codePage;
487 info->unicodeLength = info->stack[info->stackTop].unicodeLength;
493 switch(info->rtfMajor)
496 ME_RTFCharAttrHook(info);
499 ME_RTFParAttrHook(info);
507 ME_StreamInFill(ME_InStream *stream)
509 stream->editstream->dwError = stream->editstream->pfnCallback(stream->editstream->dwCookie,
511 sizeof(stream->buffer),
516 static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stream)
520 int from, to, to2, nUndoMode;
522 int nEventMask = editor->nEventMask;
523 ME_InStream inStream;
525 TRACE("stream==%p hWnd==%p format==0x%X\n", stream, editor->hWnd, (UINT)format);
526 editor->nEventMask = 0;
528 ME_GetSelection(editor, &from, &to);
529 if (format & SFF_SELECTION) {
530 style = ME_GetSelectionInsertStyle(editor);
532 ME_InternalDeleteText(editor, from, to-from);
535 style = editor->pBuffer->pDefaultStyle;
536 ME_AddRefStyle(style);
537 SendMessageA(editor->hWnd, EM_SETSEL, 0, 0);
538 ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor));
540 ME_ClearTempStyle(editor);
541 /* FIXME restore default paragraph formatting ! */
544 nUndoMode = editor->nUndoMode;
545 editor->nUndoMode = umIgnore;
547 inStream.editstream = stream;
548 inStream.editstream->dwError = 0;
554 /* Check if it's really RTF, and if it is not, use plain text */
555 ME_StreamInFill(&inStream);
556 if (!inStream.editstream->dwError)
558 if (strncmp(inStream.buffer, "{\\rtf1", 6) && strncmp(inStream.buffer, "{\\urtf", 6))
566 if (!inStream.editstream->dwError)
568 if (format & SF_RTF) {
569 /* setup the RTF parser */
570 memset(&parser, 0, sizeof parser);
571 RTFSetEditStream(&parser, &inStream);
572 parser.rtfFormat = format&(SF_TEXT|SF_RTF);
573 parser.hwndEdit = editor->hWnd;
574 parser.editor = editor;
575 parser.style = style;
578 RTFSetReadHook(&parser, ME_RTFReadHook);
583 RTFFlushOutputBuffer(&parser);
586 style = parser.style;
588 else if (format & SF_TEXT)
589 ME_StreamInText(editor, format, &inStream, style);
591 ERR("EM_STREAMIN without SF_TEXT or SF_RTF\n");
592 ME_GetSelection(editor, &to, &to2);
593 /* put the cursor at the top */
594 if (!(format & SFF_SELECTION))
595 SendMessageA(editor->hWnd, EM_SETSEL, 0, 0);
598 /* FIXME where to put cursor now ? */
602 editor->nUndoMode = nUndoMode;
603 pUI = ME_AddUndoItem(editor, diUndoDeleteRun, NULL);
604 TRACE("from %d to %d\n", from, to);
605 if (pUI && from < to)
610 ME_CommitUndo(editor);
611 ME_ReleaseStyle(style);
612 editor->nEventMask = nEventMask;
613 InvalidateRect(editor->hWnd, NULL, TRUE);
614 ME_UpdateRepaint(editor);
615 if (!(format & SFF_SELECTION)) {
616 ME_ClearTempStyle(editor);
618 ME_MoveCaret(editor);
619 ME_SendSelChange(editor);
626 ME_FindItemAtOffset(ME_TextEditor *editor, ME_DIType nItemType, int nOffset, int *nItemOffset)
628 ME_DisplayItem *item = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph);
630 while (item && item->member.para.next_para->member.para.nCharOfs <= nOffset)
631 item = ME_FindItemFwd(item, diParagraph);
636 nOffset -= item->member.para.nCharOfs;
637 if (nItemType == diParagraph) {
639 *nItemOffset = nOffset;
644 item = ME_FindItemFwd(item, diRun);
645 } while (item && (item->member.run.nCharOfs + ME_StrLen(item->member.run.strText) <= nOffset));
647 nOffset -= item->member.run.nCharOfs;
649 *nItemOffset = nOffset;
656 ME_FindText(ME_TextEditor *editor, DWORD flags, CHARRANGE *chrg, WCHAR *text, CHARRANGE *chrgText)
658 int nStart = chrg->cpMin;
659 int nLen = lstrlenW(text);
660 ME_DisplayItem *item = ME_FindItemAtOffset(editor, diRun, nStart, &nStart);
661 ME_DisplayItem *para;
669 chrgText->cpMin = chrgText->cpMax = chrg->cpMin;
673 if (!(flags & FR_DOWN))
674 FIXME("Backward search not implemented\n");
675 if (!(flags & FR_MATCHCASE))
676 FIXME("Case-insensitive search not implemented\n");
677 if (flags & ~(FR_DOWN | FR_MATCHCASE))
678 FIXME("Flags 0x%08lx not implemented\n", flags & ~(FR_DOWN | FR_MATCHCASE));
680 para = ME_GetParagraph(item);
681 while (item && para->member.para.nCharOfs + item->member.run.nCharOfs + nStart + nLen < chrg->cpMax)
683 ME_DisplayItem *pCurItem = item;
684 int nCurStart = nStart;
687 while (pCurItem->member.run.strText->szData[nCurStart + nMatched] == text[nMatched])
690 if (nMatched == nLen)
692 nStart += para->member.para.nCharOfs + item->member.run.nCharOfs;
695 chrgText->cpMin = nStart;
696 chrgText->cpMax = nStart + nLen;
700 if (nCurStart + nMatched == ME_StrLen(pCurItem->member.run.strText))
702 pCurItem = ME_FindItemFwd(pCurItem, diRun);
703 nCurStart = -nMatched;
707 if (nStart == ME_StrLen(item->member.run.strText))
709 item = ME_FindItemFwd(item, diRun);
710 para = ME_GetParagraph(item);
718 ME_TextEditor *ME_MakeEditor(HWND hWnd) {
719 ME_TextEditor *ed = ALLOC_OBJ(ME_TextEditor);
723 ed->pBuffer = ME_MakeText();
725 ME_MakeFirstParagraph(hDC, ed->pBuffer);
726 ReleaseDC(hWnd, hDC);
727 ed->bCaretShown = FALSE;
729 ed->pCursors = ALLOC_N_OBJ(ME_Cursor, ed->nCursors);
730 ed->pCursors[0].pRun = ME_FindItemFwd(ed->pBuffer->pFirst, diRun);
731 ed->pCursors[0].nOffset = 0;
732 ed->pCursors[1].pRun = ME_FindItemFwd(ed->pBuffer->pFirst, diRun);
733 ed->pCursors[1].nOffset = 0;
734 ed->nLastTotalLength = ed->nTotalLength = 0;
737 ed->rgbBackColor = -1;
738 ed->bCaretAtEnd = FALSE;
741 ed->pUndoStack = ed->pRedoStack = NULL;
742 ed->nUndoMode = umAddToUndo;
744 ed->nLastSelStart = ed->nLastSelEnd = 0;
746 for (i=0; i<HFONT_CACHE_SIZE; i++)
748 ed->pFontCache[i].nRefs = 0;
749 ed->pFontCache[i].nAge = 0;
750 ed->pFontCache[i].hFont = NULL;
752 ME_CheckCharOffsets(ed);
756 typedef struct tagME_GlobalDestStruct
760 } ME_GlobalDestStruct;
762 static DWORD CALLBACK ME_AppendToHGLOBAL(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
764 ME_GlobalDestStruct *pData = (ME_GlobalDestStruct *)dwCookie;
768 nMaxSize = GlobalSize(pData->hData);
769 if (pData->nLength+cb+1 >= cb)
771 /* round up to 2^17 */
772 int nNewSize = (((nMaxSize+cb+1)|0x1FFFF)+1) & 0xFFFE0000;
773 pData->hData = GlobalReAlloc(pData->hData, nNewSize, 0);
775 pDest = (BYTE *)GlobalLock(pData->hData);
776 memcpy(pDest + pData->nLength, lpBuff, cb);
777 pData->nLength += cb;
778 pDest[pData->nLength] = '\0';
779 GlobalUnlock(pData->hData);
785 static DWORD CALLBACK ME_ReadFromHGLOBALUnicode(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
787 ME_GlobalDestStruct *pData = (ME_GlobalDestStruct *)dwCookie;
792 pDest = (WORD *)lpBuff;
793 pSrc = (WORD *)GlobalLock(pData->hData);
794 for (i = 0; i<cb && pSrc[pData->nLength+i]; i++) {
795 pDest[i] = pSrc[pData->nLength+i];
799 GlobalUnlock(pData->hData);
803 static DWORD CALLBACK ME_ReadFromHGLOBALRTF(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
805 ME_GlobalDestStruct *pData = (ME_GlobalDestStruct *)dwCookie;
810 pSrc = (BYTE *)GlobalLock(pData->hData);
811 for (i = 0; i<cb && pSrc[pData->nLength+i]; i++) {
812 pDest[i] = pSrc[pData->nLength+i];
816 GlobalUnlock(pData->hData);
821 void ME_DestroyEditor(ME_TextEditor *editor)
823 ME_DisplayItem *pFirst = editor->pBuffer->pFirst;
824 ME_DisplayItem *p = pFirst, *pNext = NULL;
827 ME_ClearTempStyle(editor);
828 ME_EmptyUndoStack(editor);
831 ME_DestroyDisplayItem(p);
834 ME_ReleaseStyle(editor->pBuffer->pDefaultStyle);
835 for (i=0; i<HFONT_CACHE_SIZE; i++)
837 if (editor->pFontCache[i].hFont)
838 DeleteObject(editor->pFontCache[i].hFont);
844 static WCHAR wszClassName[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '2', '0', 'W', 0};
845 static WCHAR wszClassName50[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '5', '0', 'W', 0};
847 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
852 case DLL_PROCESS_ATTACH:
853 DisableThreadLibraryCalls(hinstDLL);
854 me_heap = HeapCreate (0, 0x10000, 0);
855 ME_RegisterEditorClass(hinstDLL);
858 case DLL_PROCESS_DETACH:
859 UnregisterClassW(wszClassName, 0);
860 UnregisterClassW(wszClassName50, 0);
861 UnregisterClassA("RichEdit20A", 0);
862 UnregisterClassA("RichEdit50A", 0);
863 HeapDestroy (me_heap);
871 #define UNSUPPORTED_MSG(e) \
873 FIXME(#e ": stub\n"); \
874 return DefWindowProcW(hWnd, msg, wParam, lParam);
876 /******************************************************************
877 * RichEditANSIWndProc (RICHED20.10)
879 LRESULT WINAPI RichEditANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
883 ME_TextEditor *editor = (ME_TextEditor *)GetWindowLongW(hWnd, 0);
884 TRACE("msg %d %08x %08lx\n", msg, wParam, lParam);
887 UNSUPPORTED_MSG(EM_AUTOURLDETECT)
888 UNSUPPORTED_MSG(EM_CHARFROMPOS)
889 UNSUPPORTED_MSG(EM_DISPLAYBAND)
890 UNSUPPORTED_MSG(EM_EXLIMITTEXT)
891 UNSUPPORTED_MSG(EM_FINDWORDBREAK)
892 UNSUPPORTED_MSG(EM_FMTLINES)
893 UNSUPPORTED_MSG(EM_FORMATRANGE)
894 UNSUPPORTED_MSG(EM_GETAUTOURLDETECT)
895 UNSUPPORTED_MSG(EM_GETBIDIOPTIONS)
896 UNSUPPORTED_MSG(EM_GETEDITSTYLE)
897 UNSUPPORTED_MSG(EM_GETFIRSTVISIBLELINE)
898 UNSUPPORTED_MSG(EM_GETIMECOMPMODE)
899 /* UNSUPPORTED_MSG(EM_GETIMESTATUS) missing in Wine headers */
900 UNSUPPORTED_MSG(EM_GETLANGOPTIONS)
901 UNSUPPORTED_MSG(EM_GETLIMITTEXT)
902 UNSUPPORTED_MSG(EM_GETLINE)
903 /* UNSUPPORTED_MSG(EM_GETOLEINTERFACE) separate stub */
904 UNSUPPORTED_MSG(EM_GETOPTIONS)
905 UNSUPPORTED_MSG(EM_GETPASSWORDCHAR)
906 UNSUPPORTED_MSG(EM_GETRECT)
907 UNSUPPORTED_MSG(EM_GETREDONAME)
908 UNSUPPORTED_MSG(EM_GETSCROLLPOS)
909 UNSUPPORTED_MSG(EM_GETTEXTMODE)
910 UNSUPPORTED_MSG(EM_GETTYPOGRAPHYOPTIONS)
911 UNSUPPORTED_MSG(EM_GETUNDONAME)
912 UNSUPPORTED_MSG(EM_GETWORDBREAKPROC)
913 UNSUPPORTED_MSG(EM_GETWORDBREAKPROCEX)
914 UNSUPPORTED_MSG(EM_GETZOOM)
915 UNSUPPORTED_MSG(EM_HIDESELECTION)
916 UNSUPPORTED_MSG(EM_LIMITTEXT) /* also known as EM_SETLIMITTEXT */
917 UNSUPPORTED_MSG(EM_LINELENGTH)
918 UNSUPPORTED_MSG(EM_PASTESPECIAL)
919 /* UNSUPPORTED_MSG(EM_POSFROMCHARS) missing in Wine headers */
920 UNSUPPORTED_MSG(EM_REQUESTRESIZE)
921 UNSUPPORTED_MSG(EM_SCROLL)
922 UNSUPPORTED_MSG(EM_SCROLLCARET)
923 UNSUPPORTED_MSG(EM_SELECTIONTYPE)
924 UNSUPPORTED_MSG(EM_SETBIDIOPTIONS)
925 UNSUPPORTED_MSG(EM_SETEDITSTYLE)
926 UNSUPPORTED_MSG(EM_SETFONTSIZE)
927 UNSUPPORTED_MSG(EM_SETLANGOPTIONS)
928 UNSUPPORTED_MSG(EM_SETOLECALLBACK)
929 UNSUPPORTED_MSG(EM_SETOPTIONS)
930 UNSUPPORTED_MSG(EM_SETPALETTE)
931 UNSUPPORTED_MSG(EM_SETPASSWORDCHAR)
932 UNSUPPORTED_MSG(EM_SETRECT)
933 UNSUPPORTED_MSG(EM_SETRECTNP)
934 UNSUPPORTED_MSG(EM_SETSCROLLPOS)
935 UNSUPPORTED_MSG(EM_SETTABSTOPS)
936 UNSUPPORTED_MSG(EM_SETTARGETDEVICE)
937 UNSUPPORTED_MSG(EM_SETTEXTMODE)
938 UNSUPPORTED_MSG(EM_SETTYPOGRAPHYOPTIONS)
939 UNSUPPORTED_MSG(EM_SETUNDOLIMIT)
940 UNSUPPORTED_MSG(EM_SETWORDBREAKPROC)
941 UNSUPPORTED_MSG(EM_SETWORDBREAKPROCEX)
942 UNSUPPORTED_MSG(EM_SHOWSCROLLBAR)
943 UNSUPPORTED_MSG(EM_SETZOOM)
944 UNSUPPORTED_MSG(WM_SETFONT)
945 UNSUPPORTED_MSG(WM_STYLECHANGING)
946 UNSUPPORTED_MSG(WM_STYLECHANGED)
947 /* UNSUPPORTED_MSG(WM_UNICHAR) FIXME missing in Wine headers */
949 /* Messages specific to Richedit controls */
952 return ME_StreamIn(editor, wParam, (EDITSTREAM*)lParam);
954 return ME_StreamOut(editor, wParam, (EDITSTREAM *)lParam);
957 UINT code = DLGC_WANTCHARS|DLGC_WANTARROWS;
958 if (GetWindowLongW(hWnd, GWL_STYLE)&ES_WANTRETURN)
959 code |= 0; /* FIXME what can we do here ? ask for messages and censor them ? */
964 CREATESTRUCTW *pcs = (CREATESTRUCTW *)lParam;
965 editor = ME_MakeEditor(hWnd);
966 SetWindowLongW(hWnd, 0, (long)editor);
967 pcs = 0; /* ignore */
970 case EM_EMPTYUNDOBUFFER:
971 ME_EmptyUndoStack(editor);
975 /* Note: wParam/lParam can be NULL */
977 PUINT pfrom = wParam ? (PUINT)wParam : &from;
978 PUINT pto = lParam ? (PUINT)lParam : &to;
979 ME_GetSelection(editor, pfrom, pto);
980 if ((*pfrom|*pto) & 0xFFFF0000)
982 return MAKELONG(*pfrom,*pto);
986 CHARRANGE *pRange = (CHARRANGE *)lParam;
987 ME_GetSelection(editor, (int *)&pRange->cpMin, (int *)&pRange->cpMax);
991 return editor->pUndoStack != NULL;
993 return editor->pRedoStack != NULL;
1002 ME_SetSelection(editor, wParam, lParam);
1004 ME_SendSelChange(editor);
1009 CHARRANGE *pRange = (CHARRANGE *)lParam;
1010 ME_SetSelection(editor, pRange->cpMin, pRange->cpMax);
1011 /* FIXME optimize */
1013 ME_SendSelChange(editor);
1018 LPWSTR wszText = (LPWSTR)lParam;
1019 SETTEXTEX *pStruct = (SETTEXTEX *)wParam;
1020 size_t len = lstrlenW(wszText);
1023 TRACE("EM_SETTEXEX - %s, flags %d, cp %d\n", debugstr_w(wszText), (int)pStruct->flags, pStruct->codepage);
1024 if (pStruct->codepage != 1200) {
1025 FIXME("EM_SETTEXTEX only supports unicode right now!\n");
1028 /* FIXME: this should support RTF strings too, according to MSDN */
1029 if (pStruct->flags & ST_SELECTION) {
1030 ME_GetSelection(editor, &from, &to);
1031 style = ME_GetSelectionInsertStyle(editor);
1032 ME_InternalDeleteText(editor, from, to - from);
1033 ME_InsertTextFromCursor(editor, 0, wszText, len, style);
1034 ME_ReleaseStyle(style);
1037 ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor));
1038 ME_InsertTextFromCursor(editor, 0, wszText, -1, editor->pBuffer->pDefaultStyle);
1041 ME_CommitUndo(editor);
1042 if (!(pStruct->flags & ST_KEEPUNDO))
1043 ME_EmptyUndoStack(editor);
1044 ME_UpdateRepaint(editor);
1047 case EM_SETBKGNDCOLOR:
1049 LRESULT lColor = ME_GetBackColor(editor);
1051 editor->rgbBackColor = -1;
1053 editor->rgbBackColor = lParam;
1054 InvalidateRect(hWnd, NULL, TRUE);
1059 return editor->nModifyStep == 0 ? 0 : 1;
1063 editor->nModifyStep = 0x80000000;
1065 editor->nModifyStep = 0;
1069 case EM_SETREADONLY:
1071 long nStyle = GetWindowLongW(hWnd, GWL_STYLE);
1073 nStyle |= ES_READONLY;
1075 nStyle &= ~ES_READONLY;
1076 SetWindowLongW(hWnd, GWL_STYLE, nStyle);
1080 case EM_SETEVENTMASK:
1081 editor->nEventMask = lParam;
1083 case EM_GETEVENTMASK:
1084 return editor->nEventMask;
1085 case EM_SETCHARFORMAT:
1087 CHARFORMAT2W buf, *p;
1088 BOOL bRepaint = TRUE;
1089 p = ME_ToCF2W(&buf, (CHARFORMAT2W *)lParam);
1091 ME_SetDefaultCharFormat(editor, p);
1092 else if (wParam == (SCF_WORD | SCF_SELECTION))
1093 FIXME("word selection not supported\n");
1094 else if (wParam == SCF_ALL)
1095 ME_SetCharFormat(editor, 0, ME_GetTextLength(editor), p);
1098 ME_GetSelection(editor, &from, &to);
1099 bRepaint = (from != to);
1100 ME_SetSelectionCharFormat(editor, p);
1102 ME_CommitUndo(editor);
1104 ME_UpdateRepaint(editor);
1107 case EM_GETCHARFORMAT:
1109 CHARFORMAT2W tmp, *dst = (CHARFORMAT2W *)lParam;
1110 if (dst->cbSize != sizeof(CHARFORMATA) &&
1111 dst->cbSize != sizeof(CHARFORMATW) &&
1112 dst->cbSize != sizeof(CHARFORMAT2A) &&
1113 dst->cbSize != sizeof(CHARFORMAT2W))
1115 tmp.cbSize = sizeof(tmp);
1117 ME_GetDefaultCharFormat(editor, &tmp);
1119 ME_GetSelectionCharFormat(editor, &tmp);
1120 ME_CopyToCFAny(dst, &tmp);
1123 case EM_SETPARAFORMAT:
1124 ME_SetSelectionParaFormat(editor, (PARAFORMAT2 *)lParam);
1125 ME_UpdateRepaint(editor);
1126 ME_CommitUndo(editor);
1128 case EM_GETPARAFORMAT:
1129 ME_GetSelectionParaFormat(editor, (PARAFORMAT2 *)lParam);
1133 int nPos = editor->nScrollPosY, nEnd= editor->nTotalLength - editor->sizeWindow.cy;
1134 nPos += 8 * lParam; /* FIXME follow the original */
1139 if (nPos != editor->nScrollPosY) {
1140 ScrollWindow(hWnd, 0, editor->nScrollPosY-nPos, NULL, NULL);
1141 editor->nScrollPosY = nPos;
1142 SetScrollPos(hWnd, SB_VERT, nPos, TRUE);
1145 return TRUE; /* Should return false if a single line richedit control */
1150 ME_GetSelection(editor, &from, &to);
1151 ME_InternalDeleteText(editor, from, to-from);
1152 ME_CommitUndo(editor);
1153 ME_UpdateRepaint(editor);
1160 LPWSTR wszText = ME_ToUnicode(hWnd, (void *)lParam);
1161 size_t len = lstrlenW(wszText);
1162 TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText));
1164 ME_GetSelection(editor, &from, &to);
1165 style = ME_GetSelectionInsertStyle(editor);
1166 ME_InternalDeleteText(editor, from, to-from);
1167 ME_InsertTextFromCursor(editor, 0, wszText, len, style);
1168 ME_ReleaseStyle(style);
1169 ME_EndToUnicode(hWnd, wszText);
1170 /* drop temporary style if line end */
1171 /* FIXME question: does abc\n mean: put abc, clear temp style, put \n? (would require a change) */
1172 if (len>0 && wszText[len-1] == '\n')
1173 ME_ClearTempStyle(editor);
1175 ME_CommitUndo(editor);
1177 ME_EmptyUndoStack(editor);
1178 ME_UpdateRepaint(editor);
1183 LPWSTR wszText = ME_ToUnicode(hWnd, (void *)lParam);
1184 TRACE("WM_SETTEXT - %s\n", (char *)(wszText)); /* debugstr_w() */
1185 ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor));
1186 /* uses default style! */
1187 ME_InsertTextFromCursor(editor, 0, wszText, -1, editor->pBuffer->pDefaultStyle);
1188 ME_EndToUnicode(hWnd, wszText);
1189 ME_CommitUndo(editor);
1190 ME_EmptyUndoStack(editor);
1191 ME_UpdateRepaint(editor);
1196 UINT nRTFFormat = RegisterClipboardFormatA("Rich Text Format");
1197 if (IsClipboardFormatAvailable(nRTFFormat))
1199 if (IsClipboardFormatAvailable(CF_UNICODETEXT))
1207 ME_GlobalDestStruct gds;
1208 UINT nRTFFormat = RegisterClipboardFormatA("Rich Text Format");
1211 if (IsClipboardFormatAvailable(nRTFFormat))
1212 cf = nRTFFormat, dwFormat = SF_RTF;
1213 else if (IsClipboardFormatAvailable(CF_UNICODETEXT))
1214 cf = CF_UNICODETEXT, dwFormat = SF_TEXT|SF_UNICODE;
1218 if (!OpenClipboard(hWnd))
1220 gds.hData = GetClipboardData(cf);
1222 es.dwCookie = (DWORD)&gds;
1223 es.pfnCallback = dwFormat == SF_RTF ? ME_ReadFromHGLOBALRTF : ME_ReadFromHGLOBALUnicode;
1224 SendMessageW(hWnd, EM_STREAMIN, dwFormat|SFF_SELECTION, (LPARAM)&es);
1236 ME_GlobalDestStruct gds;
1238 if (!OpenClipboard(hWnd))
1242 ME_GetSelection(editor, &from, &to);
1243 pars = ME_CountParagraphsBetween(editor, from, to);
1244 hData = GlobalAlloc(GMEM_MOVEABLE, sizeof(WCHAR)*(to-from+pars+1));
1245 data = (WCHAR *)GlobalLock(hData);
1246 ME_GetTextW(editor, data, from, to-from, TRUE);
1247 GlobalUnlock(hData);
1249 gds.hData = GlobalAlloc(GMEM_MOVEABLE, 0);
1251 es.dwCookie = (DWORD)&gds;
1252 es.pfnCallback = ME_AppendToHGLOBAL;
1253 SendMessageW(hWnd, EM_STREAMOUT, SFF_SELECTION|SF_RTF, (LPARAM)&es);
1254 GlobalReAlloc(gds.hData, gds.nLength+1, 0);
1256 SetClipboardData(CF_UNICODETEXT, hData);
1257 SetClipboardData(RegisterClipboardFormatA("Rich Text Format"), gds.hData);
1262 ME_InternalDeleteText(editor, from, to-from);
1263 ME_CommitUndo(editor);
1264 ME_UpdateRepaint(editor);
1268 case WM_GETTEXTLENGTH:
1269 return ME_GetTextLength(editor);
1270 case EM_GETTEXTLENGTHEX:
1271 return ME_GetTextLengthEx(editor, (GETTEXTLENGTHEX *)wParam);
1274 TEXTRANGEW tr; /* W and A differ only by rng->lpstrText */
1276 tr.chrg.cpMax = wParam-1;
1277 tr.lpstrText = (WCHAR *)lParam;
1278 return RichEditANSIWndProc(hWnd, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
1282 GETTEXTEX *ex = (GETTEXTEX*)wParam;
1285 FIXME("Unhandled EM_GETTEXTEX flags 0x%lx\n",ex->flags);
1287 if (IsWindowUnicode(hWnd))
1288 return ME_GetTextW(editor, (LPWSTR)lParam, 0, ex->cb, FALSE);
1291 LPWSTR buffer = HeapAlloc(GetProcessHeap(),0,ex->cb*sizeof(WCHAR));
1292 DWORD buflen = ex->cb;
1296 buflen = ME_GetTextW(editor, buffer, 0, buflen, FALSE);
1297 rc = WideCharToMultiByte(ex->codepage, flags, buffer, buflen, (LPSTR)lParam, ex->cb, ex->lpDefaultChar, ex->lpUsedDefaultChar);
1299 HeapFree(GetProcessHeap(),0,buffer);
1306 TEXTRANGEW tr; /* W and A differ only by rng->lpstrText */
1307 ME_GetSelection(editor, &from, &to);
1308 tr.chrg.cpMin = from;
1310 tr.lpstrText = (WCHAR *)lParam;
1311 return RichEditANSIWndProc(hWnd, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
1313 case EM_GETTEXTRANGE:
1315 TEXTRANGEW *rng = (TEXTRANGEW *)lParam;
1316 if (IsWindowUnicode(hWnd))
1317 return ME_GetTextW(editor, rng->lpstrText, rng->chrg.cpMin, rng->chrg.cpMax-rng->chrg.cpMin, FALSE);
1320 int nLen = rng->chrg.cpMax-rng->chrg.cpMin;
1321 WCHAR *p = ALLOC_N_OBJ(WCHAR, nLen+1);
1322 int nChars = ME_GetTextW(editor, p, rng->chrg.cpMin, nLen, FALSE);
1323 /* FIXME this is a potential security hole (buffer overrun)
1324 if you know more about wchar->mbyte conversion please explain
1326 WideCharToMultiByte(CP_ACP, 0, p, nChars+1, (char *)rng->lpstrText, nLen+1, NULL, NULL);
1330 return ME_GetTextW(editor, rng->lpstrText, rng->chrg.cpMin, rng->chrg.cpMax-rng->chrg.cpMin, FALSE);
1332 case EM_GETLINECOUNT:
1334 ME_DisplayItem *item = editor->pBuffer->pFirst->next;
1337 while (item != editor->pBuffer->pLast)
1339 assert(item->type == diParagraph);
1340 nRows += item->member.para.nRows;
1341 item = item->member.para.next_para;
1343 return max(1, nRows);
1345 case EM_LINEFROMCHAR:
1348 return ME_RowNumberFromCharOfs(editor, ME_GetCursorOfs(editor, 1));
1350 return ME_RowNumberFromCharOfs(editor, wParam);
1352 case EM_EXLINEFROMCHAR:
1354 return ME_RowNumberFromCharOfs(editor, lParam);
1358 ME_DisplayItem *item, *para;
1361 item = ME_FindItemBack(editor->pCursors[0].pRun, diStartRow);
1363 item = ME_FindRowWithNumber(editor, wParam);
1366 para = ME_GetParagraph(item);
1367 item = ME_FindItemFwd(item, diRun);
1368 return para->member.para.nCharOfs + item->member.run.nCharOfs;
1372 FINDTEXTA *ft = (FINDTEXTA *)lParam;
1373 int nChars = MultiByteToWideChar(CP_ACP, 0, ft->lpstrText, -1, NULL, 0);
1376 if ((tmp = ALLOC_N_OBJ(WCHAR, nChars)) != NULL)
1377 MultiByteToWideChar(CP_ACP, 0, ft->lpstrText, -1, tmp, nChars);
1378 return ME_FindText(editor, wParam, &ft->chrg, tmp, NULL);
1382 FINDTEXTEXA *ex = (FINDTEXTEXA *)lParam;
1383 int nChars = MultiByteToWideChar(CP_ACP, 0, ex->lpstrText, -1, NULL, 0);
1386 if ((tmp = ALLOC_N_OBJ(WCHAR, nChars)) != NULL)
1387 MultiByteToWideChar(CP_ACP, 0, ex->lpstrText, -1, tmp, nChars);
1388 return ME_FindText(editor, wParam, &ex->chrg, tmp, &ex->chrgText);
1392 FINDTEXTW *ft = (FINDTEXTW *)lParam;
1393 return ME_FindText(editor, wParam, &ft->chrg, ft->lpstrText, NULL);
1395 case EM_FINDTEXTEXW:
1397 FINDTEXTEXW *ex = (FINDTEXTEXW *)lParam;
1398 return ME_FindText(editor, wParam, &ex->chrg, ex->lpstrText, &ex->chrgText);
1401 ME_CommitUndo(editor);
1402 ME_WrapMarkedParagraphs(editor);
1403 ME_MoveCaret(editor);
1406 ME_DestroyEditor(editor);
1407 SetWindowLongW(hWnd, 0, 0);
1409 case WM_LBUTTONDOWN:
1411 ME_LButtonDown(editor, (short)LOWORD(lParam), (short)HIWORD(lParam));
1415 if (GetCapture() == hWnd)
1416 ME_MouseMove(editor, (short)LOWORD(lParam), (short)HIWORD(lParam));
1419 if (GetCapture() == hWnd)
1423 hDC = BeginPaint(hWnd, &ps);
1424 ME_PaintContent(editor, hDC, FALSE, &ps.rcPaint);
1425 EndPaint(hWnd, &ps);
1428 ME_ShowCaret(editor);
1429 ME_SendOldNotify(editor, EN_SETFOCUS);
1432 ME_HideCaret(editor);
1433 ME_SendOldNotify(editor, EN_KILLFOCUS);
1437 HDC hDC = (HDC)wParam;
1439 COLORREF rgbBG = ME_GetBackColor(editor);
1440 if (GetUpdateRect(hWnd,&rc,TRUE))
1442 HBRUSH hbr = CreateSolidBrush(rgbBG);
1443 FillRect(hDC, &rc, hbr);
1449 TRACE("editor wnd command = %d\n", LOWORD(wParam));
1452 if (ME_ArrowKey(editor, LOWORD(wParam), GetKeyState(VK_CONTROL)<0)) {
1453 ME_CommitUndo(editor);
1454 ME_EnsureVisible(editor, editor->pCursors[0].pRun);
1456 ME_MoveCaret(editor);
1460 if (GetKeyState(VK_CONTROL)<0)
1462 if (LOWORD(wParam)=='W')
1466 ME_GetSelectionCharFormat(editor, &chf);
1467 ME_DumpStyleToBuf(&chf, buf);
1468 MessageBoxA(NULL, buf, "Style dump", MB_OK);
1470 if (LOWORD(wParam)=='Q')
1472 ME_CheckCharOffsets(editor);
1479 if (GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_READONLY) {
1480 MessageBeep(MB_ICONERROR);
1481 return 0; /* FIXME really 0 ? */
1483 wstr = LOWORD(wParam);
1484 if (((unsigned)wstr)>=' ' || wstr=='\r' || wstr=='\t') {
1485 /* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */
1486 ME_Style *style = ME_GetInsertStyle(editor, 0);
1487 ME_SaveTempStyle(editor);
1488 ME_InsertTextFromCursor(editor, 0, &wstr, 1, style);
1489 ME_ReleaseStyle(style);
1490 ME_CommitUndo(editor);
1491 ME_UpdateRepaint(editor);
1497 int nPos = editor->nScrollPosY;
1498 si.cbSize = sizeof(SCROLLINFO);
1499 si.fMask = SIF_PAGE|SIF_POS|SIF_RANGE|SIF_TRACKPOS;
1500 GetScrollInfo(hWnd, SB_VERT, &si);
1501 switch(LOWORD(wParam)) {
1503 nPos -= 24; /* FIXME follow the original */
1504 if (nPos<0) nPos = 0;
1508 int nEnd = editor->nTotalLength - editor->sizeWindow.cy;
1509 nPos += 24; /* FIXME follow the original */
1510 if (nPos>=nEnd) nPos = nEnd;
1514 nPos -= editor->sizeWindow.cy;
1515 if (nPos<0) nPos = 0;
1518 nPos += editor->sizeWindow.cy;
1519 if (nPos>=editor->nTotalLength) nPos = editor->nTotalLength-1;
1522 case SB_THUMBPOSITION:
1523 nPos = si.nTrackPos;
1526 if (nPos != editor->nScrollPosY) {
1527 ScrollWindow(hWnd, 0, editor->nScrollPosY-nPos, NULL, NULL);
1528 editor->nScrollPosY = nPos;
1529 SetScrollPos(hWnd, SB_VERT, nPos, TRUE);
1536 int gcWheelDelta = 0, nPos = editor->nScrollPosY, nEnd = editor->nTotalLength - editor->sizeWindow.cy;
1537 UINT pulScrollLines;
1538 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES,0, &pulScrollLines, 0);
1539 gcWheelDelta -= GET_WHEEL_DELTA_WPARAM(wParam);
1540 if (abs(gcWheelDelta) >= WHEEL_DELTA && pulScrollLines)
1541 nPos += pulScrollLines * (gcWheelDelta / WHEEL_DELTA) * 8; /* FIXME follow the original */
1546 if (nPos != editor->nScrollPosY) {
1547 ScrollWindow(hWnd, 0, editor->nScrollPosY-nPos, NULL, NULL);
1548 editor->nScrollPosY = nPos;
1549 SetScrollPos(hWnd, SB_VERT, nPos, TRUE);
1556 ME_MarkAllForWrapping(editor);
1557 ME_WrapMarkedParagraphs(editor);
1558 ME_UpdateScrollBar(editor);
1560 return DefWindowProcW(hWnd, msg, wParam, lParam);
1562 case EM_GETOLEINTERFACE:
1564 LPVOID *ppvObj = (LPVOID*) lParam;
1565 FIXME("EM_GETOLEINTERFACE %p: stub\n", ppvObj);
1566 return CreateIRichEditOle(ppvObj);
1570 return DefWindowProcW(hWnd, msg, wParam, lParam);
1575 /******************************************************************
1576 * RichEdit10ANSIWndProc (RICHED20.9)
1578 LRESULT WINAPI RichEdit10ANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1580 /* FIXME: this is NOT the same as 2.0 version */
1581 return RichEditANSIWndProc(hWnd, msg, wParam, lParam);
1584 void ME_SendOldNotify(ME_TextEditor *editor, int nCode)
1586 HWND hWnd = editor->hWnd;
1587 SendMessageA(GetParent(hWnd), WM_COMMAND, (nCode<<16)|GetWindowLongW(hWnd, GWLP_ID), (LPARAM)hWnd);
1590 int ME_CountParagraphsBetween(ME_TextEditor *editor, int from, int to)
1592 ME_DisplayItem *item = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph);
1595 while(item && item->member.para.next_para->member.para.nCharOfs <= from)
1596 item = item->member.para.next_para;
1599 while(item && item->member.para.next_para->member.para.nCharOfs <= to) {
1600 item = item->member.para.next_para;
1607 int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int nStart, int nChars, int bCRLF)
1609 ME_DisplayItem *item = ME_FindItemAtOffset(editor, diRun, nStart, &nStart);
1620 int nLen = ME_StrLen(item->member.run.strText) - nStart;
1623 CopyMemory(buffer, item->member.run.strText->szData + nStart, sizeof(WCHAR)*nLen);
1630 item = ME_FindItemFwd(item, diRun);
1633 while(nChars && item)
1635 int nLen = ME_StrLen(item->member.run.strText);
1639 if (item->member.run.nFlags & MERF_ENDPARA)
1649 CopyMemory(buffer, item->member.run.strText->szData, sizeof(WCHAR)*nLen);
1659 item = ME_FindItemFwd(item, diRun);
1665 void ME_RegisterEditorClass(HINSTANCE hInstance)
1671 wcW.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
1672 wcW.lpfnWndProc = RichEditANSIWndProc;
1675 wcW.hInstance = NULL; /* hInstance would register DLL-local class */
1677 wcW.hCursor = LoadCursorW(NULL, MAKEINTRESOURCEW(IDC_IBEAM));
1678 wcW.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
1679 wcW.lpszMenuName = NULL;
1680 wcW.lpszClassName = wszClassName;
1681 bResult = RegisterClassW(&wcW);
1683 wcW.lpszClassName = wszClassName50;
1684 bResult = RegisterClassW(&wcW);
1687 wcA.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
1688 wcA.lpfnWndProc = RichEditANSIWndProc;
1691 wcA.hInstance = NULL; /* hInstance would register DLL-local class */
1693 wcA.hCursor = LoadCursorW(NULL, MAKEINTRESOURCEW(IDC_IBEAM));
1694 wcA.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
1695 wcA.lpszMenuName = NULL;
1696 wcA.lpszClassName = "RichEdit20A";
1697 bResult = RegisterClassA(&wcA);
1699 wcA.lpszClassName = "RichEdit50A";
1700 bResult = RegisterClassA(&wcA);
1703 /******************************************************************
1704 * CreateTextServices (RICHED20.4)
1706 * FIXME should be ITextHost instead of void*
1708 HRESULT WINAPI CreateTextServices(IUnknown *punkOuter, void *pITextHost,
1712 /* FIXME should support aggregation */
1714 return CLASS_E_NOAGGREGATION;
1716 return E_FAIL; /* E_NOTIMPL isn't allowed by MSDN */
1719 /******************************************************************
1720 * REExtendedRegisterClass (RICHED20.8)
1722 * FIXME undocumented
1724 void WINAPI REExtendedRegisterClass(void)