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)
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;
618 InvalidateRect(editor->hWnd, NULL, TRUE);
619 ME_UpdateRepaint(editor);
621 if (!(format & SFF_SELECTION)) {
622 ME_ClearTempStyle(editor);
624 ME_MoveCaret(editor);
625 ME_SendSelChange(editor);
632 ME_FindItemAtOffset(ME_TextEditor *editor, ME_DIType nItemType, int nOffset, int *nItemOffset)
634 ME_DisplayItem *item = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph);
636 while (item && item->member.para.next_para->member.para.nCharOfs <= nOffset)
637 item = ME_FindItemFwd(item, diParagraph);
642 nOffset -= item->member.para.nCharOfs;
643 if (nItemType == diParagraph) {
645 *nItemOffset = nOffset;
650 item = ME_FindItemFwd(item, diRun);
651 } while (item && (item->member.run.nCharOfs + ME_StrLen(item->member.run.strText) <= nOffset));
653 nOffset -= item->member.run.nCharOfs;
655 *nItemOffset = nOffset;
662 ME_FindText(ME_TextEditor *editor, DWORD flags, CHARRANGE *chrg, WCHAR *text, CHARRANGE *chrgText)
664 int nStart = chrg->cpMin;
665 int nLen = lstrlenW(text);
666 ME_DisplayItem *item = ME_FindItemAtOffset(editor, diRun, nStart, &nStart);
667 ME_DisplayItem *para;
675 chrgText->cpMin = chrgText->cpMax = chrg->cpMin;
679 if (!(flags & FR_DOWN))
680 FIXME("Backward search not implemented\n");
681 if (!(flags & FR_MATCHCASE))
682 FIXME("Case-insensitive search not implemented\n");
683 if (flags & ~(FR_DOWN | FR_MATCHCASE))
684 FIXME("Flags 0x%08lx not implemented\n", flags & ~(FR_DOWN | FR_MATCHCASE));
686 para = ME_GetParagraph(item);
687 while (item && para->member.para.nCharOfs + item->member.run.nCharOfs + nStart + nLen < chrg->cpMax)
689 ME_DisplayItem *pCurItem = item;
690 int nCurStart = nStart;
693 while (pCurItem->member.run.strText->szData[nCurStart + nMatched] == text[nMatched])
696 if (nMatched == nLen)
698 nStart += para->member.para.nCharOfs + item->member.run.nCharOfs;
701 chrgText->cpMin = nStart;
702 chrgText->cpMax = nStart + nLen;
706 if (nCurStart + nMatched == ME_StrLen(pCurItem->member.run.strText))
708 pCurItem = ME_FindItemFwd(pCurItem, diRun);
709 nCurStart = -nMatched;
713 if (nStart == ME_StrLen(item->member.run.strText))
715 item = ME_FindItemFwd(item, diRun);
716 para = ME_GetParagraph(item);
724 ME_TextEditor *ME_MakeEditor(HWND hWnd) {
725 ME_TextEditor *ed = ALLOC_OBJ(ME_TextEditor);
729 ed->bEmulateVersion10 = FALSE;
730 ed->pBuffer = ME_MakeText();
732 ME_MakeFirstParagraph(hDC, ed->pBuffer);
733 ReleaseDC(hWnd, hDC);
734 ed->bCaretShown = FALSE;
736 ed->pCursors = ALLOC_N_OBJ(ME_Cursor, ed->nCursors);
737 ed->pCursors[0].pRun = ME_FindItemFwd(ed->pBuffer->pFirst, diRun);
738 ed->pCursors[0].nOffset = 0;
739 ed->pCursors[1].pRun = ME_FindItemFwd(ed->pBuffer->pFirst, diRun);
740 ed->pCursors[1].nOffset = 0;
741 ed->nLastTotalLength = ed->nTotalLength = 0;
744 ed->rgbBackColor = -1;
745 ed->bCaretAtEnd = FALSE;
748 ed->pUndoStack = ed->pRedoStack = NULL;
749 ed->nUndoMode = umAddToUndo;
751 ed->nLastSelStart = ed->nLastSelEnd = 0;
753 ed->nZoomNumerator = ed->nZoomDenominator = 0;
755 GetClientRect(hWnd, &ed->rcFormat);
756 for (i=0; i<HFONT_CACHE_SIZE; i++)
758 ed->pFontCache[i].nRefs = 0;
759 ed->pFontCache[i].nAge = 0;
760 ed->pFontCache[i].hFont = NULL;
762 ME_CheckCharOffsets(ed);
766 typedef struct tagME_GlobalDestStruct
770 } ME_GlobalDestStruct;
772 static DWORD CALLBACK ME_AppendToHGLOBAL(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
774 ME_GlobalDestStruct *pData = (ME_GlobalDestStruct *)dwCookie;
778 nMaxSize = GlobalSize(pData->hData);
779 if (pData->nLength+cb+1 >= cb)
781 /* round up to 2^17 */
782 int nNewSize = (((nMaxSize+cb+1)|0x1FFFF)+1) & 0xFFFE0000;
783 pData->hData = GlobalReAlloc(pData->hData, nNewSize, 0);
785 pDest = (BYTE *)GlobalLock(pData->hData);
786 memcpy(pDest + pData->nLength, lpBuff, cb);
787 pData->nLength += cb;
788 pDest[pData->nLength] = '\0';
789 GlobalUnlock(pData->hData);
795 static DWORD CALLBACK ME_ReadFromHGLOBALUnicode(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
797 ME_GlobalDestStruct *pData = (ME_GlobalDestStruct *)dwCookie;
802 pDest = (WORD *)lpBuff;
803 pSrc = (WORD *)GlobalLock(pData->hData);
804 for (i = 0; i<cb && pSrc[pData->nLength+i]; i++) {
805 pDest[i] = pSrc[pData->nLength+i];
809 GlobalUnlock(pData->hData);
813 static DWORD CALLBACK ME_ReadFromHGLOBALRTF(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
815 ME_GlobalDestStruct *pData = (ME_GlobalDestStruct *)dwCookie;
820 pSrc = (BYTE *)GlobalLock(pData->hData);
821 for (i = 0; i<cb && pSrc[pData->nLength+i]; i++) {
822 pDest[i] = pSrc[pData->nLength+i];
826 GlobalUnlock(pData->hData);
831 void ME_DestroyEditor(ME_TextEditor *editor)
833 ME_DisplayItem *pFirst = editor->pBuffer->pFirst;
834 ME_DisplayItem *p = pFirst, *pNext = NULL;
837 ME_ClearTempStyle(editor);
838 ME_EmptyUndoStack(editor);
841 ME_DestroyDisplayItem(p);
844 ME_ReleaseStyle(editor->pBuffer->pDefaultStyle);
845 for (i=0; i<HFONT_CACHE_SIZE; i++)
847 if (editor->pFontCache[i].hFont)
848 DeleteObject(editor->pFontCache[i].hFont);
854 static WCHAR wszClassName[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '2', '0', 'W', 0};
855 static WCHAR wszClassName50[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '5', '0', 'W', 0};
857 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
862 case DLL_PROCESS_ATTACH:
863 DisableThreadLibraryCalls(hinstDLL);
864 me_heap = HeapCreate (0, 0x10000, 0);
865 ME_RegisterEditorClass(hinstDLL);
868 case DLL_PROCESS_DETACH:
869 UnregisterClassW(wszClassName, 0);
870 UnregisterClassW(wszClassName50, 0);
871 UnregisterClassA("RichEdit20A", 0);
872 UnregisterClassA("RichEdit50A", 0);
873 HeapDestroy (me_heap);
881 #define UNSUPPORTED_MSG(e) \
883 FIXME(#e ": stub\n"); \
884 return DefWindowProcW(hWnd, msg, wParam, lParam);
886 static const char * const edit_messages[] = {
915 "EM_SETPASSWORDCHAR",
916 "EM_EMPTYUNDOBUFFER",
917 "EM_GETFIRSTVISIBLELINE",
919 "EM_SETWORDBREAKPROC",
920 "EM_GETWORDBREAKPROC",
921 "EM_GETPASSWORDCHAR",
929 static const char * const richedit_messages[] = {
940 "EM_GETOLEINTERFACE",
952 "EM_SETTARGETDEVICE",
960 "EM_GETWORDBREAKPROCEX",
961 "EM_SETWORDBREAKPROCEX",
963 "EM_UNKNOWN_USER_83",
968 "EM_STOPGROUPTYPING",
972 "EM_GETAUTOURLDETECT",
975 "EM_GETTEXTLENGTHEX",
978 "EM_UNKNOWN_USER_98",
979 "EM_UNKNOWN_USER_99",
982 "EM_SETWORDWRAPMODE",
983 "EM_GETWORDWRAPMODE",
989 "EM_UNKNOWN_USER_109",
990 "EM_UNKNOWN_USER_110",
991 "EM_UNKNOWN_USER_111",
992 "EM_UNKNOWN_USER_112",
993 "EM_UNKNOWN_USER_113",
994 "EM_UNKNOWN_USER_114",
995 "EM_UNKNOWN_USER_115",
996 "EM_UNKNOWN_USER_116",
997 "EM_UNKNOWN_USER_117",
998 "EM_UNKNOWN_USER_118",
999 "EM_UNKNOWN_USER_119",
1000 "EM_SETLANGOPTIONS",
1001 "EM_GETLANGOPTIONS",
1002 "EM_GETIMECOMPMODE",
1006 "EM_SETIMEMODEBIAS",
1011 get_msg_name(UINT msg)
1013 if (msg >= EM_GETSEL && msg <= EM_SETLIMITTEXT)
1014 return edit_messages[msg - EM_GETSEL];
1015 if (msg >= EM_CANPASTE && msg <= EM_GETIMEMODEBIAS)
1016 return richedit_messages[msg - EM_CANPASTE];
1020 /******************************************************************
1021 * RichEditANSIWndProc (RICHED20.10)
1023 LRESULT WINAPI RichEditANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
1025 ME_TextEditor *editor = (ME_TextEditor *)GetWindowLongW(hWnd, 0);
1027 TRACE("hWnd %p msg %d (%s) %08x %08lx\n",
1028 hWnd, msg, get_msg_name(msg), wParam, lParam);
1032 UNSUPPORTED_MSG(EM_AUTOURLDETECT)
1033 UNSUPPORTED_MSG(EM_DISPLAYBAND)
1034 UNSUPPORTED_MSG(EM_EXLIMITTEXT)
1035 UNSUPPORTED_MSG(EM_FINDWORDBREAK)
1036 UNSUPPORTED_MSG(EM_FMTLINES)
1037 UNSUPPORTED_MSG(EM_FORMATRANGE)
1038 UNSUPPORTED_MSG(EM_GETAUTOURLDETECT)
1039 UNSUPPORTED_MSG(EM_GETBIDIOPTIONS)
1040 UNSUPPORTED_MSG(EM_GETEDITSTYLE)
1041 UNSUPPORTED_MSG(EM_GETFIRSTVISIBLELINE)
1042 UNSUPPORTED_MSG(EM_GETIMECOMPMODE)
1043 /* UNSUPPORTED_MSG(EM_GETIMESTATUS) missing in Wine headers */
1044 UNSUPPORTED_MSG(EM_GETLANGOPTIONS)
1045 UNSUPPORTED_MSG(EM_GETLIMITTEXT)
1046 UNSUPPORTED_MSG(EM_GETLINE)
1047 /* UNSUPPORTED_MSG(EM_GETOLEINTERFACE) separate stub */
1048 UNSUPPORTED_MSG(EM_GETOPTIONS)
1049 UNSUPPORTED_MSG(EM_GETPASSWORDCHAR)
1050 UNSUPPORTED_MSG(EM_GETREDONAME)
1051 UNSUPPORTED_MSG(EM_GETSCROLLPOS)
1052 UNSUPPORTED_MSG(EM_GETTEXTMODE)
1053 UNSUPPORTED_MSG(EM_GETTYPOGRAPHYOPTIONS)
1054 UNSUPPORTED_MSG(EM_GETUNDONAME)
1055 UNSUPPORTED_MSG(EM_GETWORDBREAKPROC)
1056 UNSUPPORTED_MSG(EM_GETWORDBREAKPROCEX)
1057 UNSUPPORTED_MSG(EM_HIDESELECTION)
1058 UNSUPPORTED_MSG(EM_LIMITTEXT) /* also known as EM_SETLIMITTEXT */
1059 UNSUPPORTED_MSG(EM_PASTESPECIAL)
1060 /* UNSUPPORTED_MSG(EM_POSFROMCHARS) missing in Wine headers */
1061 UNSUPPORTED_MSG(EM_REQUESTRESIZE)
1062 UNSUPPORTED_MSG(EM_SCROLL)
1063 UNSUPPORTED_MSG(EM_SCROLLCARET)
1064 UNSUPPORTED_MSG(EM_SELECTIONTYPE)
1065 UNSUPPORTED_MSG(EM_SETBIDIOPTIONS)
1066 UNSUPPORTED_MSG(EM_SETEDITSTYLE)
1067 UNSUPPORTED_MSG(EM_SETFONTSIZE)
1068 UNSUPPORTED_MSG(EM_SETLANGOPTIONS)
1069 UNSUPPORTED_MSG(EM_SETOLECALLBACK)
1070 UNSUPPORTED_MSG(EM_SETOPTIONS)
1071 UNSUPPORTED_MSG(EM_SETPALETTE)
1072 UNSUPPORTED_MSG(EM_SETPASSWORDCHAR)
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;
1134 case WM_UNDO: /* FIXME: actually not the same */
1143 ME_SetSelection(editor, wParam, lParam);
1145 ME_SendSelChange(editor);
1150 CHARRANGE *pRange = (CHARRANGE *)lParam;
1151 TRACE("EM_EXSETSEL (%ld,%ld)\n", pRange->cpMin, pRange->cpMax);
1152 ME_SetSelection(editor, pRange->cpMin, pRange->cpMax);
1153 /* FIXME optimize */
1155 ME_SendSelChange(editor);
1160 LPWSTR wszText = (LPWSTR)lParam;
1161 SETTEXTEX *pStruct = (SETTEXTEX *)wParam;
1162 size_t len = lstrlenW(wszText);
1165 TRACE("EM_SETTEXEX - %s, flags %d, cp %d\n", debugstr_w(wszText), (int)pStruct->flags, pStruct->codepage);
1166 if (pStruct->codepage != 1200) {
1167 FIXME("EM_SETTEXTEX only supports unicode right now!\n");
1170 /* FIXME: this should support RTF strings too, according to MSDN */
1171 if (pStruct->flags & ST_SELECTION) {
1172 ME_GetSelection(editor, &from, &to);
1173 style = ME_GetSelectionInsertStyle(editor);
1174 ME_InternalDeleteText(editor, from, to - from);
1175 ME_InsertTextFromCursor(editor, 0, wszText, len, style);
1176 ME_ReleaseStyle(style);
1179 ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor));
1180 ME_InsertTextFromCursor(editor, 0, wszText, -1, editor->pBuffer->pDefaultStyle);
1183 ME_CommitUndo(editor);
1184 if (!(pStruct->flags & ST_KEEPUNDO))
1185 ME_EmptyUndoStack(editor);
1186 ME_UpdateRepaint(editor);
1189 case EM_SETBKGNDCOLOR:
1191 LRESULT lColor = ME_GetBackColor(editor);
1193 editor->rgbBackColor = -1;
1195 editor->rgbBackColor = lParam;
1196 if (editor->bRedraw)
1198 InvalidateRect(hWnd, NULL, TRUE);
1204 return editor->nModifyStep == 0 ? 0 : 1;
1208 editor->nModifyStep = 0x80000000;
1210 editor->nModifyStep = 0;
1214 case EM_SETREADONLY:
1216 long nStyle = GetWindowLongW(hWnd, GWL_STYLE);
1218 nStyle |= ES_READONLY;
1220 nStyle &= ~ES_READONLY;
1221 SetWindowLongW(hWnd, GWL_STYLE, nStyle);
1225 case EM_SETEVENTMASK:
1226 editor->nEventMask = lParam;
1228 case EM_GETEVENTMASK:
1229 return editor->nEventMask;
1230 case EM_SETCHARFORMAT:
1232 CHARFORMAT2W buf, *p;
1233 BOOL bRepaint = TRUE;
1234 p = ME_ToCF2W(&buf, (CHARFORMAT2W *)lParam);
1236 ME_SetDefaultCharFormat(editor, p);
1237 else if (wParam == (SCF_WORD | SCF_SELECTION))
1238 FIXME("EM_SETCHARFORMAT: word selection not supported\n");
1239 else if (wParam == SCF_ALL)
1240 ME_SetCharFormat(editor, 0, ME_GetTextLength(editor), p);
1243 ME_GetSelection(editor, &from, &to);
1244 bRepaint = (from != to);
1245 ME_SetSelectionCharFormat(editor, p);
1247 ME_CommitUndo(editor);
1249 ME_UpdateRepaint(editor);
1252 case EM_GETCHARFORMAT:
1254 CHARFORMAT2W tmp, *dst = (CHARFORMAT2W *)lParam;
1255 if (dst->cbSize != sizeof(CHARFORMATA) &&
1256 dst->cbSize != sizeof(CHARFORMATW) &&
1257 dst->cbSize != sizeof(CHARFORMAT2A) &&
1258 dst->cbSize != sizeof(CHARFORMAT2W))
1260 tmp.cbSize = sizeof(tmp);
1262 ME_GetDefaultCharFormat(editor, &tmp);
1264 ME_GetSelectionCharFormat(editor, &tmp);
1265 ME_CopyToCFAny(dst, &tmp);
1268 case EM_SETPARAFORMAT:
1269 ME_SetSelectionParaFormat(editor, (PARAFORMAT2 *)lParam);
1270 ME_UpdateRepaint(editor);
1271 ME_CommitUndo(editor);
1273 case EM_GETPARAFORMAT:
1274 ME_GetSelectionParaFormat(editor, (PARAFORMAT2 *)lParam);
1278 int nPos = editor->nScrollPosY, nEnd= editor->nTotalLength - editor->sizeWindow.cy;
1279 nPos += 8 * lParam; /* FIXME follow the original */
1284 if (nPos != editor->nScrollPosY) {
1285 if (editor->bRedraw)
1287 ScrollWindow(hWnd, 0, editor->nScrollPosY-nPos, NULL, NULL);
1288 SetScrollPos(hWnd, SB_VERT, nPos, TRUE);
1291 editor->nScrollPosY = nPos;
1293 return TRUE; /* Should return false if a single line richedit control */
1298 ME_GetSelection(editor, &from, &to);
1299 ME_InternalDeleteText(editor, from, to-from);
1300 ME_CommitUndo(editor);
1301 ME_UpdateRepaint(editor);
1308 LPWSTR wszText = ME_ToUnicode(hWnd, (void *)lParam);
1309 size_t len = lstrlenW(wszText);
1310 TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText));
1312 ME_GetSelection(editor, &from, &to);
1313 style = ME_GetSelectionInsertStyle(editor);
1314 ME_InternalDeleteText(editor, from, to-from);
1315 ME_InsertTextFromCursor(editor, 0, wszText, len, style);
1316 ME_ReleaseStyle(style);
1317 ME_EndToUnicode(hWnd, wszText);
1318 /* drop temporary style if line end */
1319 /* FIXME question: does abc\n mean: put abc, clear temp style, put \n? (would require a change) */
1320 if (len>0 && wszText[len-1] == '\n')
1321 ME_ClearTempStyle(editor);
1323 ME_CommitUndo(editor);
1325 ME_EmptyUndoStack(editor);
1326 ME_UpdateRepaint(editor);
1331 ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor));
1334 LPWSTR wszText = ME_ToUnicode(hWnd, (void *)lParam);
1335 TRACE("WM_SETTEXT lParam==%lx\n",lParam);
1336 TRACE("WM_SETTEXT - %s\n", debugstr_w(wszText)); /* debugstr_w() */
1337 if (lstrlenW(wszText) > 0)
1339 /* uses default style! */
1340 ME_InsertTextFromCursor(editor, 0, wszText, -1, editor->pBuffer->pDefaultStyle);
1342 ME_EndToUnicode(hWnd, wszText);
1345 TRACE("WM_SETTEXT - NULL\n");
1346 ME_CommitUndo(editor);
1347 ME_EmptyUndoStack(editor);
1348 ME_UpdateRepaint(editor);
1353 UINT nRTFFormat = RegisterClipboardFormatA("Rich Text Format");
1354 if (IsClipboardFormatAvailable(nRTFFormat))
1356 if (IsClipboardFormatAvailable(CF_UNICODETEXT))
1364 ME_GlobalDestStruct gds;
1365 UINT nRTFFormat = RegisterClipboardFormatA("Rich Text Format");
1368 if (IsClipboardFormatAvailable(nRTFFormat))
1369 cf = nRTFFormat, dwFormat = SF_RTF;
1370 else if (IsClipboardFormatAvailable(CF_UNICODETEXT))
1371 cf = CF_UNICODETEXT, dwFormat = SF_TEXT|SF_UNICODE;
1375 if (!OpenClipboard(hWnd))
1377 gds.hData = GetClipboardData(cf);
1379 es.dwCookie = (DWORD)&gds;
1380 es.pfnCallback = dwFormat == SF_RTF ? ME_ReadFromHGLOBALRTF : ME_ReadFromHGLOBALUnicode;
1381 SendMessageW(hWnd, EM_STREAMIN, dwFormat|SFF_SELECTION, (LPARAM)&es);
1393 ME_GlobalDestStruct gds;
1395 if (!OpenClipboard(hWnd))
1399 ME_GetSelection(editor, &from, &to);
1400 pars = ME_CountParagraphsBetween(editor, from, to);
1401 hData = GlobalAlloc(GMEM_MOVEABLE, sizeof(WCHAR)*(to-from+pars+1));
1402 data = (WCHAR *)GlobalLock(hData);
1403 ME_GetTextW(editor, data, from, to-from, TRUE);
1404 GlobalUnlock(hData);
1406 gds.hData = GlobalAlloc(GMEM_MOVEABLE, 0);
1408 es.dwCookie = (DWORD)&gds;
1409 es.pfnCallback = ME_AppendToHGLOBAL;
1410 SendMessageW(hWnd, EM_STREAMOUT, SFF_SELECTION|SF_RTF, (LPARAM)&es);
1411 GlobalReAlloc(gds.hData, gds.nLength+1, 0);
1413 SetClipboardData(CF_UNICODETEXT, hData);
1414 SetClipboardData(RegisterClipboardFormatA("Rich Text Format"), gds.hData);
1419 ME_InternalDeleteText(editor, from, to-from);
1420 ME_CommitUndo(editor);
1421 ME_UpdateRepaint(editor);
1425 case WM_GETTEXTLENGTH:
1426 return ME_GetTextLength(editor);
1427 case EM_GETTEXTLENGTHEX:
1428 return ME_GetTextLengthEx(editor, (GETTEXTLENGTHEX *)wParam);
1431 TEXTRANGEW tr; /* W and A differ only by rng->lpstrText */
1433 tr.chrg.cpMax = wParam-1;
1434 tr.lpstrText = (WCHAR *)lParam;
1435 return RichEditANSIWndProc(hWnd, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
1439 GETTEXTEX *ex = (GETTEXTEX*)wParam;
1442 if (ex->flags & ~(GT_SELECTION | GT_USECRLF))
1443 FIXME("GETTEXTEX flags 0x%08lx not supported\n", ex->flags & ~(GT_SELECTION | GT_USECRLF));
1445 if (ex->flags & GT_SELECTION)
1447 ME_GetSelection(editor, &nStart, &nCount);
1449 nCount = min(nCount, ex->cb - 1);
1454 nCount = ex->cb - 1;
1456 if (ex->codepage == 1200 || IsWindowUnicode(hWnd))
1458 nCount = min(nCount, ex->cb / sizeof(WCHAR) - 1);
1459 return ME_GetTextW(editor, (LPWSTR)lParam, nStart, nCount, ex->flags & GT_USECRLF);
1463 LPWSTR buffer = HeapAlloc(GetProcessHeap(), 0, (nCount + 1) * sizeof(WCHAR));
1464 DWORD buflen = ex->cb;
1468 buflen = ME_GetTextW(editor, buffer, nStart, nCount, ex->flags & GT_USECRLF);
1469 rc = WideCharToMultiByte(ex->codepage, flags, buffer, buflen, (LPSTR)lParam, ex->cb, ex->lpDefaultChar, ex->lpUsedDefaultChar);
1471 HeapFree(GetProcessHeap(),0,buffer);
1478 TEXTRANGEW tr; /* W and A differ only by rng->lpstrText */
1479 ME_GetSelection(editor, &from, &to);
1480 tr.chrg.cpMin = from;
1482 tr.lpstrText = (WCHAR *)lParam;
1483 return RichEditANSIWndProc(hWnd, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
1485 case EM_GETTEXTRANGE:
1487 TEXTRANGEW *rng = (TEXTRANGEW *)lParam;
1488 if (IsWindowUnicode(hWnd))
1489 return ME_GetTextW(editor, rng->lpstrText, rng->chrg.cpMin, rng->chrg.cpMax-rng->chrg.cpMin, editor->bEmulateVersion10);
1492 int nLen = rng->chrg.cpMax-rng->chrg.cpMin;
1493 WCHAR *p = ALLOC_N_OBJ(WCHAR, nLen+1);
1494 int nChars = ME_GetTextW(editor, p, rng->chrg.cpMin, nLen, editor->bEmulateVersion10);
1495 /* FIXME this is a potential security hole (buffer overrun)
1496 if you know more about wchar->mbyte conversion please explain
1498 WideCharToMultiByte(CP_ACP, 0, p, nChars+1, (char *)rng->lpstrText, nLen+1, NULL, NULL);
1503 case EM_GETLINECOUNT:
1505 ME_DisplayItem *item = editor->pBuffer->pFirst->next;
1508 while (item != editor->pBuffer->pLast)
1510 assert(item->type == diParagraph);
1511 nRows += item->member.para.nRows;
1512 item = item->member.para.next_para;
1514 TRACE("EM_GETLINECOUNT: nRows==%d\n", nRows);
1515 return max(1, nRows);
1517 case EM_LINEFROMCHAR:
1520 return ME_RowNumberFromCharOfs(editor, ME_GetCursorOfs(editor, 1));
1522 return ME_RowNumberFromCharOfs(editor, wParam);
1524 case EM_EXLINEFROMCHAR:
1526 return ME_RowNumberFromCharOfs(editor, lParam);
1530 ME_DisplayItem *item, *para;
1534 item = ME_FindItemBack(editor->pCursors[0].pRun, diStartRow);
1536 item = ME_FindRowWithNumber(editor, wParam);
1539 para = ME_GetParagraph(item);
1540 item = ME_FindItemFwd(item, diRun);
1541 nCharOfs = para->member.para.nCharOfs + item->member.run.nCharOfs;
1542 TRACE("EM_LINEINDEX: nCharOfs==%d\n", nCharOfs);
1547 ME_DisplayItem *item, *item_end;
1550 if (wParam > ME_GetTextLength(editor))
1554 FIXME("EM_LINELENGTH: returning number of unselected characters on lines with selection unsupported.\n");
1557 item = ME_FindItemAtOffset(editor, diRun, wParam, NULL);
1558 item = ME_RowStart(item);
1559 item_end = ME_RowEnd(item);
1562 /* Empty buffer, no runs */
1567 nChars = ME_CharOfsFromRunOfs(editor, item_end, ME_StrLen(item_end->member.run.strText));
1568 nChars -= ME_CharOfsFromRunOfs(editor, item, 0);
1570 TRACE("EM_LINELENGTH(%d)==%d\n",wParam, nChars);
1575 FINDTEXTA *ft = (FINDTEXTA *)lParam;
1576 int nChars = MultiByteToWideChar(CP_ACP, 0, ft->lpstrText, -1, NULL, 0);
1579 if ((tmp = ALLOC_N_OBJ(WCHAR, nChars)) != NULL)
1580 MultiByteToWideChar(CP_ACP, 0, ft->lpstrText, -1, tmp, nChars);
1581 return ME_FindText(editor, wParam, &ft->chrg, tmp, NULL);
1585 FINDTEXTEXA *ex = (FINDTEXTEXA *)lParam;
1586 int nChars = MultiByteToWideChar(CP_ACP, 0, ex->lpstrText, -1, NULL, 0);
1589 if ((tmp = ALLOC_N_OBJ(WCHAR, nChars)) != NULL)
1590 MultiByteToWideChar(CP_ACP, 0, ex->lpstrText, -1, tmp, nChars);
1591 return ME_FindText(editor, wParam, &ex->chrg, tmp, &ex->chrgText);
1595 FINDTEXTW *ft = (FINDTEXTW *)lParam;
1596 return ME_FindText(editor, wParam, &ft->chrg, ft->lpstrText, NULL);
1598 case EM_FINDTEXTEXW:
1600 FINDTEXTEXW *ex = (FINDTEXTEXW *)lParam;
1601 return ME_FindText(editor, wParam, &ex->chrg, ex->lpstrText, &ex->chrgText);
1604 if (!wParam || !lParam)
1606 *(int *)wParam = editor->nZoomNumerator;
1607 *(int *)lParam = editor->nZoomDenominator;
1610 return ME_SetZoom(editor, wParam, lParam);
1611 case EM_CHARFROMPOS:
1612 return ME_CharFromPos(editor, ((POINTL *)lParam)->x, ((POINTL *)lParam)->y);
1614 ME_CommitUndo(editor);
1615 ME_WrapMarkedParagraphs(editor);
1616 ME_MoveCaret(editor);
1619 ME_DestroyEditor(editor);
1620 SetWindowLongW(hWnd, 0, 0);
1622 case WM_LBUTTONDOWN:
1624 ME_LButtonDown(editor, (short)LOWORD(lParam), (short)HIWORD(lParam));
1628 if (GetCapture() == hWnd)
1629 ME_MouseMove(editor, (short)LOWORD(lParam), (short)HIWORD(lParam));
1632 if (GetCapture() == hWnd)
1636 if (editor->bRedraw)
1641 hDC = BeginPaint(hWnd, &ps);
1642 ME_PaintContent(editor, hDC, FALSE, &ps.rcPaint);
1643 EndPaint(hWnd, &ps);
1647 ME_ShowCaret(editor);
1648 ME_SendOldNotify(editor, EN_SETFOCUS);
1651 ME_HideCaret(editor);
1652 ME_SendOldNotify(editor, EN_KILLFOCUS);
1656 if (editor->bRedraw)
1658 HDC hDC = (HDC)wParam;
1660 COLORREF rgbBG = ME_GetBackColor(editor);
1661 if (GetUpdateRect(hWnd,&rc,TRUE))
1663 HBRUSH hbr = CreateSolidBrush(rgbBG);
1664 FillRect(hDC, &rc, hbr);
1671 TRACE("editor wnd command = %d\n", LOWORD(wParam));
1674 if (ME_ArrowKey(editor, LOWORD(wParam), GetKeyState(VK_CONTROL)<0)) {
1675 ME_CommitUndo(editor);
1676 ME_EnsureVisible(editor, editor->pCursors[0].pRun);
1678 ME_MoveCaret(editor);
1682 if (GetKeyState(VK_CONTROL)<0)
1684 if (LOWORD(wParam)=='W')
1688 ME_GetSelectionCharFormat(editor, &chf);
1689 ME_DumpStyleToBuf(&chf, buf);
1690 MessageBoxA(NULL, buf, "Style dump", MB_OK);
1692 if (LOWORD(wParam)=='Q')
1694 ME_CheckCharOffsets(editor);
1700 WCHAR wstr = LOWORD(wParam);
1704 case 3: /* Ctrl-C */
1705 SendMessageW(editor->hWnd, WM_COPY, 0, 0);
1709 if (GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_READONLY) {
1710 MessageBeep(MB_ICONERROR);
1711 return 0; /* FIXME really 0 ? */
1716 case 1: /* Ctrl-A */
1717 ME_SetSelection(editor, 0, -1);
1719 case 22: /* Ctrl-V */
1720 SendMessageW(editor->hWnd, WM_PASTE, 0, 0);
1722 case 24: /* Ctrl-X */
1723 SendMessageW(editor->hWnd, WM_CUT, 0, 0);
1725 case 25: /* Ctrl-Y */
1726 SendMessageW(editor->hWnd, EM_REDO, 0, 0);
1728 case 26: /* Ctrl-Z */
1729 SendMessageW(editor->hWnd, EM_UNDO, 0, 0);
1732 if (((unsigned)wstr)>=' ' || wstr=='\r' || wstr=='\t') {
1733 /* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */
1734 ME_Style *style = ME_GetInsertStyle(editor, 0);
1735 ME_SaveTempStyle(editor);
1736 ME_InsertTextFromCursor(editor, 0, &wstr, 1, style);
1737 ME_ReleaseStyle(style);
1738 ME_CommitUndo(editor);
1739 ME_UpdateRepaint(editor);
1745 int nPos = editor->nScrollPosY;
1746 si.cbSize = sizeof(SCROLLINFO);
1747 si.fMask = SIF_PAGE|SIF_POS|SIF_RANGE|SIF_TRACKPOS;
1748 GetScrollInfo(hWnd, SB_VERT, &si);
1749 switch(LOWORD(wParam)) {
1751 nPos -= 24; /* FIXME follow the original */
1752 if (nPos<0) nPos = 0;
1756 int nEnd = editor->nTotalLength - editor->sizeWindow.cy;
1757 nPos += 24; /* FIXME follow the original */
1758 if (nPos>=nEnd) nPos = nEnd;
1762 nPos -= editor->sizeWindow.cy;
1763 if (nPos<0) nPos = 0;
1766 nPos += editor->sizeWindow.cy;
1767 if (nPos>=editor->nTotalLength) nPos = editor->nTotalLength-1;
1770 case SB_THUMBPOSITION:
1771 nPos = si.nTrackPos;
1774 if (nPos != editor->nScrollPosY) {
1775 if (editor->bRedraw)
1777 ScrollWindow(hWnd, 0, editor->nScrollPosY-nPos, NULL, NULL);
1778 SetScrollPos(hWnd, SB_VERT, nPos, TRUE);
1781 editor->nScrollPosY = nPos;
1787 int gcWheelDelta = 0, nPos = editor->nScrollPosY, nEnd = editor->nTotalLength - editor->sizeWindow.cy;
1788 UINT pulScrollLines;
1789 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES,0, &pulScrollLines, 0);
1790 gcWheelDelta -= GET_WHEEL_DELTA_WPARAM(wParam);
1791 if (abs(gcWheelDelta) >= WHEEL_DELTA && pulScrollLines)
1792 nPos += pulScrollLines * (gcWheelDelta / WHEEL_DELTA) * 8; /* FIXME follow the original */
1797 if (nPos != editor->nScrollPosY) {
1798 if (editor->bRedraw)
1800 ScrollWindow(hWnd, 0, editor->nScrollPosY-nPos, NULL, NULL);
1801 SetScrollPos(hWnd, SB_VERT, nPos, TRUE);
1804 editor->nScrollPosY = nPos;
1810 *((RECT *)lParam) = editor->rcFormat;
1818 RECT *rc = (RECT *)lParam;
1822 editor->rcFormat.left += rc->left;
1823 editor->rcFormat.top += rc->top;
1824 editor->rcFormat.right += rc->right;
1825 editor->rcFormat.bottom += rc->bottom;
1829 editor->rcFormat = *rc;
1834 GetClientRect(hWnd, &editor->rcFormat);
1836 if (msg != EM_SETRECTNP)
1837 ME_RewrapRepaint(editor);
1841 editor->bRedraw = wParam;
1845 GetClientRect(hWnd, &editor->rcFormat);
1846 ME_RewrapRepaint(editor);
1847 return DefWindowProcW(hWnd, msg, wParam, lParam);
1849 case EM_GETOLEINTERFACE:
1851 LPVOID *ppvObj = (LPVOID*) lParam;
1852 FIXME("EM_GETOLEINTERFACE %p: stub\n", ppvObj);
1853 return CreateIRichEditOle(ppvObj);
1857 return DefWindowProcW(hWnd, msg, wParam, lParam);
1863 /******************************************************************
1864 * RichEdit10ANSIWndProc (RICHED20.9)
1866 LRESULT WINAPI RichEdit10ANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1870 /* FIXME: this is NOT the same as 2.0 version */
1871 result = RichEditANSIWndProc(hWnd, msg, wParam, lParam);
1872 if (msg == WM_NCCREATE)
1874 ME_TextEditor *editor = (ME_TextEditor *)GetWindowLongW(hWnd, 0);
1876 editor->bEmulateVersion10 = TRUE;
1877 editor->pBuffer->pLast->member.para.nCharOfs = 2;
1882 void ME_SendOldNotify(ME_TextEditor *editor, int nCode)
1884 HWND hWnd = editor->hWnd;
1885 SendMessageA(GetParent(hWnd), WM_COMMAND, (nCode<<16)|GetWindowLongW(hWnd, GWLP_ID), (LPARAM)hWnd);
1888 int ME_CountParagraphsBetween(ME_TextEditor *editor, int from, int to)
1890 ME_DisplayItem *item = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph);
1893 while(item && item->member.para.next_para->member.para.nCharOfs <= from)
1894 item = item->member.para.next_para;
1897 while(item && item->member.para.next_para->member.para.nCharOfs <= to) {
1898 item = item->member.para.next_para;
1905 int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int nStart, int nChars, int bCRLF)
1907 ME_DisplayItem *item = ME_FindItemAtOffset(editor, diRun, nStart, &nStart);
1918 int nLen = ME_StrLen(item->member.run.strText) - nStart;
1921 CopyMemory(buffer, item->member.run.strText->szData + nStart, sizeof(WCHAR)*nLen);
1928 item = ME_FindItemFwd(item, diRun);
1931 while(nChars && item)
1933 int nLen = ME_StrLen(item->member.run.strText);
1937 if (item->member.run.nFlags & MERF_ENDPARA)
1948 CopyMemory(buffer, item->member.run.strText->szData, sizeof(WCHAR)*nLen);
1958 item = ME_FindItemFwd(item, diRun);
1964 void ME_RegisterEditorClass(HINSTANCE hInstance)
1970 wcW.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
1971 wcW.lpfnWndProc = RichEditANSIWndProc;
1974 wcW.hInstance = NULL; /* hInstance would register DLL-local class */
1976 wcW.hCursor = LoadCursorW(NULL, MAKEINTRESOURCEW(IDC_IBEAM));
1977 wcW.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
1978 wcW.lpszMenuName = NULL;
1979 wcW.lpszClassName = wszClassName;
1980 bResult = RegisterClassW(&wcW);
1982 wcW.lpszClassName = wszClassName50;
1983 bResult = RegisterClassW(&wcW);
1986 wcA.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
1987 wcA.lpfnWndProc = RichEditANSIWndProc;
1990 wcA.hInstance = NULL; /* hInstance would register DLL-local class */
1992 wcA.hCursor = LoadCursorW(NULL, MAKEINTRESOURCEW(IDC_IBEAM));
1993 wcA.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
1994 wcA.lpszMenuName = NULL;
1995 wcA.lpszClassName = "RichEdit20A";
1996 bResult = RegisterClassA(&wcA);
1998 wcA.lpszClassName = "RichEdit50A";
1999 bResult = RegisterClassA(&wcA);
2002 /******************************************************************
2003 * CreateTextServices (RICHED20.4)
2005 * FIXME should be ITextHost instead of void*
2007 HRESULT WINAPI CreateTextServices(IUnknown *punkOuter, void *pITextHost,
2011 /* FIXME should support aggregation */
2013 return CLASS_E_NOAGGREGATION;
2015 return E_FAIL; /* E_NOTIMPL isn't allowed by MSDN */
2018 /******************************************************************
2019 * REExtendedRegisterClass (RICHED20.8)
2021 * FIXME undocumented
2023 void WINAPI REExtendedRegisterClass(void)