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
41 - EM_GETCHARFORMAT (partly done)
43 - EM_GETFIRSTVISIBLELINE
44 - EM_GETIMECOLOR 1.0asian
45 - EM_GETIMECOMPMODE 2.0
46 - EM_GETIMEOPTIONS 1.0asian
48 - EM_GETLANGOPTIONS 2.0
51 - EM_GETLINECOUNT returns number of rows, not of paragraphs
56 - EM_GETPUNCTUATION 1.0asian
60 + EM_GETSELTEXT (ANSI&Unicode)
63 ? + EM_GETTEXTRANGE (ANSI&Unicode)
66 - EM_GETWORDBREAKPROCEX
67 - EM_GETWORDWRAPMODE 1.0asian
78 + EM_REPLACESEL (proper style?) ANSI&Unicode
83 - EM_SETCHARFORMAT (partly done, no ANSI)
84 + EM_SETEVENTMASK (few notifications supported)
85 - EM_SETIMECOLOR 1.0asian
86 - EM_SETIMEOPTIONS 1.0asian
87 - EM_SETLANGOPTIONS 2.0
89 + EM_SETMODIFY (not sure if implementation is correct)
93 - EM_SETPUNCTUATION 1.0asian
94 + EM_SETREADONLY no beep on modification attempt
96 - EM_SETRECTNP (EM_SETRECT without repainting) - not supported in RICHEDIT
100 - EM_SETUNDOLIMIT 2.0
101 - EM_SETWORDBREAKPROC
102 - EM_SETWORDBREAKPROCEX
103 - EM_SETWORDWRAPMODE 1.0asian
104 - EM_STOPGROUPTYPING 2.0
110 - WM_COPY (lame implementation, no RTF support)
111 - WM_CUT (lame implementation, no RTF support)
112 + WM_GETDLGCODE (the current implementation is incomplete)
113 + WM_GETTEXT (ANSI&Unicode)
114 + WM_GETTEXTLENGTH (ANSI version sucks)
117 + WM_SETTEXT (resets undo stack !) (proper style?) ANSI&Unicode
119 - WM_STYLECHANGED (things like read-only flag)
124 * EN_CHANGE (sent from the wrong place)
141 * EN_UPDATE (sent from the wrong place)
149 - ES_DISABLENOSCROLL (scrollbar is always visible)
150 - ES_EX_NOCALLOLEINIT
152 - ES_MULTILINE (currently single line controls aren't supported)
154 - ES_READONLY (I'm not sure if beeping is the proper behaviour)
160 - ES_WANTRETURN (don't know how to do WM_GETDLGCODE part)
167 * RICHED20 TODO (incomplete):
170 * - add remaining CHARFORMAT/PARAFORMAT fields
171 * - right/center align should strip spaces from the beginning
172 * - more advanced navigation (Ctrl-arrows, PageUp/PageDn)
174 * - pictures (not just smiling faces that lack API support ;-) )
176 * - calculate heights of pictures (half-done)
177 * - EM_STREAMIN/EM_STREAMOUT
178 * - horizontal scrolling (not even started)
179 * - fix scrollbars and refresh (it sucks bigtime)
180 * - hysteresis during wrapping (related to scrollbars appearing/disappearing)
181 * - should remember maximum row width for wrap hysteresis
183 * - how to implement EM_FORMATRANGE and EM_DISPLAYBAND ? (Mission Impossible)
184 * - italic cursor with italic fonts
186 * - most notifications aren't sent at all (the most important ones are)
187 * - when should EN_SELCHANGE be sent after text change ? (before/after EN_UPDATE?)
188 * - WM_SETTEXT may use wrong style (but I'm 80% sure it's OK)
189 * - EM_GETCHARFORMAT with SCF_SELECTION may not behave 100% like in original (but very close)
190 * - bugs in end-of-text handling (the gray bar) could get me in jail ;-)
191 * - determination of row size
192 * - end-of-paragraph marks should be of reasonable size
194 * Bugs that are probably fixed, but not so easy to verify:
195 * - EN_UPDATE/EN_CHANGE are handled very incorrectly (should be OK now)
196 * - undo for ME_JoinParagraphs doesn't store paragraph format ? (it does)
197 * - check/fix artificial EOL logic (bCursorAtEnd, hardly logical)
198 * - caret shouldn't be displayed when selection isn't empty
199 * - check refcounting in style management functions (looks perfect now, but no bugs is suspicious)
200 * - undo for setting default format (done, might be buggy)
201 * - styles might be not released properly (looks like they work like charm, but who knows?
209 #define NO_SHLWAPI_STREAM
214 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
217 HANDLE me_heap = NULL;
219 void DoWrap(ME_TextEditor *editor) {
220 HDC hDC = GetDC(editor->hWnd);
221 ME_DisplayItem *item;
223 HWND hWnd = editor->hWnd;
224 int yLength = editor->nTotalLength;
225 int nSelFrom, nSelTo;
226 int nMinSel, nMaxSel;
228 ME_GetSelection(editor, &nSelFrom, &nSelTo);
230 nMinSel = nSelFrom < editor->nOldSelFrom ? nSelFrom : editor->nOldSelFrom;
231 nMaxSel = nSelTo > editor->nOldSelTo ? nSelTo : editor->nOldSelTo;
233 ME_InitContext(&c, editor, hDC);
236 item = editor->pBuffer->pFirst->next;
237 while(item != editor->pBuffer->pLast) {
238 int para_from, para_to;
239 BOOL bRedraw = FALSE;
241 para_from = item->member.para.nCharOfs;
242 para_to = item->member.para.next_para->member.para.nCharOfs;
244 if (para_from <= nMaxSel && para_to >= nMinSel && nMinSel != nMaxSel)
247 assert(item->type == diParagraph);
248 if (!(item->member.para.nFlags & MEPF_WRAPPED)
249 || (item->member.para.nYPos != c.pt.y))
251 item->member.para.nYPos = c.pt.y;
253 ME_WrapTextParagraph(&c, item);
256 item->member.para.nFlags |= MEPF_REDRAW;
258 c.pt.y = item->member.para.nYPos + item->member.para.nHeight;
259 item = item->member.para.next_para;
261 editor->sizeWindow.cx = c.rcView.right-c.rcView.left;
262 editor->sizeWindow.cy = c.rcView.bottom-c.rcView.top;
263 editor->nTotalLength = c.pt.y-c.rcView.top;
265 ME_UpdateScrollBar(editor, -1);
266 ME_EnsureVisible(editor, editor->pCursors[0].pRun);
268 /* FIXME this should be marked for update too somehow, so that painting happens in ME_PaintContent */
269 if (yLength != c.pt.y-c.rcView.top) {
271 rc.left = c.rcView.left;
272 rc.right = c.rcView.right;
274 rc.bottom = c.rcView.bottom;
275 InvalidateRect(editor->hWnd, &rc, FALSE);
276 UpdateWindow(editor->hWnd);
279 editor->nOldSelFrom = nSelFrom;
280 editor->nOldSelTo = nSelTo;
281 /* PatBlt(hDC, 0, c.pt.y, c.rcView.right, c.rcView.bottom, BLACKNESS);*/
283 ME_DestroyContext(&c);
284 ReleaseDC(hWnd, hDC);
287 ME_TextBuffer *ME_MakeText() {
289 ME_TextBuffer *buf = ALLOC_OBJ(ME_TextBuffer);
291 ME_DisplayItem *p1 = ME_MakeDI(diTextStart);
292 ME_DisplayItem *p2 = ME_MakeDI(diTextEnd);
298 p1->member.para.next_para = p2;
299 p2->member.para.prev_para = p1;
300 p2->member.para.nCharOfs = 0;
304 buf->pCharStyle = NULL;
309 static LRESULT ME_StreamIn(HWND hwnd, DWORD format, EDITSTREAM *stream)
313 TRACE("%p %p\n", stream, hwnd);
315 /* setup the RTF parser */
316 memset(&parser, 0, sizeof parser);
317 RTFSetEditStream(&parser, stream);
318 parser.rtfFormat = format&(SF_TEXT|SF_RTF);
319 parser.hwndEdit = hwnd;
326 RTFFlushOutputBuffer(&parser);
328 /* put the cursor at the top */
329 SendMessageA(hwnd, EM_SETSEL, 0, 0);
334 ME_TextEditor *ME_MakeEditor(HWND hWnd) {
335 ME_TextEditor *ed = ALLOC_OBJ(ME_TextEditor);
339 ed->pBuffer = ME_MakeText();
341 ME_MakeFirstParagraph(hDC, ed->pBuffer);
342 ReleaseDC(hWnd, hDC);
343 ed->bCaretShown = FALSE;
345 ed->pCursors = ALLOC_N_OBJ(ME_Cursor, ed->nCursors);
346 ed->pCursors[0].pRun = ME_FindItemFwd(ed->pBuffer->pFirst, diRun);
347 ed->pCursors[0].nOffset = 0;
348 ed->pCursors[1].pRun = ME_FindItemFwd(ed->pBuffer->pFirst, diRun);
349 ed->pCursors[1].nOffset = 0;
350 ed->nTotalLength = 0;
354 ed->rgbBackColor = -1;
355 ed->bCaretAtEnd = FALSE;
358 ed->pUndoStack = ed->pRedoStack = NULL;
359 ed->nUndoMode = umAddToUndo;
361 for (i=0; i<HFONT_CACHE_SIZE; i++)
363 ed->pFontCache[i].nRefs = 0;
364 ed->pFontCache[i].nAge = 0;
365 ed->pFontCache[i].hFont = NULL;
367 ME_CheckCharOffsets(ed);
371 void ME_DestroyEditor(ME_TextEditor *editor)
373 ME_DisplayItem *pFirst = editor->pBuffer->pFirst;
374 ME_DisplayItem *p = pFirst, *pNext = NULL;
377 ME_ClearTempStyle(editor);
378 ME_EmptyUndoStack(editor);
381 ME_DestroyDisplayItem(p);
384 ME_ReleaseStyle(editor->pBuffer->pDefaultStyle);
385 for (i=0; i<HFONT_CACHE_SIZE; i++)
387 if (editor->pFontCache[i].hFont)
388 DeleteObject(editor->pFontCache[i].hFont);
394 #define UNSUPPORTED_MSG(e) \
396 FIXME(#e ": stub\n"); \
397 return DefWindowProcW(hWnd, msg, wParam, lParam);
399 /******************************************************************
400 * RichEditANSIWndProc (RICHED20.10)
402 LRESULT WINAPI RichEditANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
406 ME_TextEditor *editor = (ME_TextEditor *)GetWindowLongW(hWnd, 0);
409 UNSUPPORTED_MSG(EM_AUTOURLDETECT)
410 UNSUPPORTED_MSG(EM_CANPASTE)
411 UNSUPPORTED_MSG(EM_CHARFROMPOS)
412 UNSUPPORTED_MSG(EM_DISPLAYBAND)
413 UNSUPPORTED_MSG(EM_EXLIMITTEXT)
414 UNSUPPORTED_MSG(EM_EXLINEFROMCHAR)
415 UNSUPPORTED_MSG(EM_FINDTEXT)
416 UNSUPPORTED_MSG(EM_FINDTEXTEX)
417 UNSUPPORTED_MSG(EM_FINDWORDBREAK)
418 UNSUPPORTED_MSG(EM_FMTLINES)
419 UNSUPPORTED_MSG(EM_FORMATRANGE)
420 UNSUPPORTED_MSG(EM_GETFIRSTVISIBLELINE)
421 UNSUPPORTED_MSG(EM_GETIMECOMPMODE)
422 /* UNSUPPORTED_MSG(EM_GETIMESTATUS) missing in Wine headers */
423 UNSUPPORTED_MSG(EM_GETLANGOPTIONS)
424 UNSUPPORTED_MSG(EM_GETLIMITTEXT)
425 UNSUPPORTED_MSG(EM_GETLINE)
426 UNSUPPORTED_MSG(EM_GETLINECOUNT)
427 /* UNSUPPORTED_MSG(EM_GETOLEINTERFACE) separate stub */
428 UNSUPPORTED_MSG(EM_GETOPTIONS)
429 UNSUPPORTED_MSG(EM_GETRECT)
430 UNSUPPORTED_MSG(EM_GETREDONAME)
431 UNSUPPORTED_MSG(EM_GETTEXTMODE)
432 UNSUPPORTED_MSG(EM_GETUNDONAME)
433 UNSUPPORTED_MSG(EM_GETWORDBREAKPROC)
434 UNSUPPORTED_MSG(EM_GETWORDBREAKPROCEX)
435 UNSUPPORTED_MSG(EM_HIDESELECTION)
436 UNSUPPORTED_MSG(EM_LIMITTEXT) /* also known as EM_SETLIMITTEXT */
437 UNSUPPORTED_MSG(EM_LINEFROMCHAR)
438 UNSUPPORTED_MSG(EM_LINEINDEX)
439 UNSUPPORTED_MSG(EM_LINELENGTH)
440 UNSUPPORTED_MSG(EM_LINESCROLL)
441 UNSUPPORTED_MSG(EM_PASTESPECIAL)
442 /* UNSUPPORTED_MSG(EM_POSFROMCHARS) missing in Wine headers */
443 UNSUPPORTED_MSG(EM_REQUESTRESIZE)
444 UNSUPPORTED_MSG(EM_SCROLL)
445 UNSUPPORTED_MSG(EM_SCROLLCARET)
446 UNSUPPORTED_MSG(EM_SELECTIONTYPE)
447 UNSUPPORTED_MSG(EM_SETLANGOPTIONS)
448 UNSUPPORTED_MSG(EM_SETOLECALLBACK)
449 UNSUPPORTED_MSG(EM_SETOPTIONS)
450 UNSUPPORTED_MSG(EM_SETRECT)
451 UNSUPPORTED_MSG(EM_SETRECTNP)
452 UNSUPPORTED_MSG(EM_SETTARGETDEVICE)
453 UNSUPPORTED_MSG(EM_SETTEXTMODE)
454 UNSUPPORTED_MSG(EM_SETUNDOLIMIT)
455 UNSUPPORTED_MSG(EM_SETWORDBREAKPROC)
456 UNSUPPORTED_MSG(EM_SETWORDBREAKPROCEX)
457 UNSUPPORTED_MSG(EM_STREAMOUT)
458 UNSUPPORTED_MSG(WM_SETFONT)
459 UNSUPPORTED_MSG(WM_PASTE)
460 UNSUPPORTED_MSG(WM_STYLECHANGING)
461 UNSUPPORTED_MSG(WM_STYLECHANGED)
462 /* UNSUPPORTED_MSG(WM_UNICHAR) FIXME missing in Wine headers */
464 /* Messages specific to Richedit controls */
467 return ME_StreamIn(hWnd, wParam, (EDITSTREAM*)lParam);
470 UINT code = DLGC_WANTCHARS|DLGC_WANTARROWS;
471 if (GetWindowLongW(hWnd, GWL_STYLE)&ES_WANTRETURN)
472 code |= 0; /* FIXME what can we do here ? ask for messages and censor them ? */
477 CREATESTRUCTW *pcs = (CREATESTRUCTW *)lParam;
478 editor = ME_MakeEditor(hWnd);
479 SetWindowLongW(hWnd, 0, (long)editor);
480 pcs = 0; /* ignore */
483 case EM_EMPTYUNDOBUFFER:
484 ME_EmptyUndoStack(editor);
488 ME_GetSelection(editor, (int *)wParam, (int *)lParam);
489 if (!((wParam|lParam) & 0xFFFF0000))
490 return (lParam<<16)|wParam;
495 CHARRANGE *pRange = (CHARRANGE *)lParam;
496 ME_GetSelection(editor, (int *)&pRange->cpMin, (int *)&pRange->cpMax);
500 return editor->pUndoStack != NULL;
502 return editor->pRedoStack != NULL;
511 ME_SetSelection(editor, wParam, lParam);
513 ME_SendSelChange(editor);
518 CHARRANGE *pRange = (CHARRANGE *)lParam;
519 ME_SetSelection(editor, pRange->cpMin, pRange->cpMax);
522 ME_SendSelChange(editor);
525 case EM_SETBKGNDCOLOR:
527 LRESULT lColor = ME_GetBackColor(editor);
529 editor->rgbBackColor = -1;
531 editor->rgbBackColor = lParam;
532 InvalidateRect(hWnd, NULL, TRUE);
537 return editor->nModifyStep == 0 ? 0 : 1;
541 editor->nModifyStep = 0x80000000;
543 editor->nModifyStep = 0;
549 long nStyle = GetWindowLongW(hWnd, GWL_STYLE);
551 nStyle |= ES_READONLY;
553 nStyle &= ~ES_READONLY;
554 SetWindowLongW(hWnd, GWL_STYLE, nStyle);
558 case EM_SETEVENTMASK:
559 editor->nEventMask = lParam;
561 case EM_GETEVENTMASK:
562 return editor->nEventMask;
563 case EM_SETCHARFORMAT:
565 CHARFORMAT2W buf, *p;
566 p = ME_ToCF2W(&buf, (CHARFORMAT2W *)lParam);
568 ME_SetDefaultCharFormat(editor, p);
569 else if (wParam == (SCF_WORD | SCF_SELECTION))
570 FIXME("word selection not supported\n");
571 else if (wParam == SCF_ALL)
572 ME_SetCharFormat(editor, 0, ME_GetTextLength(editor), p);
574 ME_SetSelectionCharFormat(editor, p);
575 ME_CommitUndo(editor);
576 ME_UpdateRepaint(editor);
579 case EM_GETCHARFORMAT:
582 tmp.cbSize = sizeof(tmp);
584 ME_GetDefaultCharFormat(editor, &tmp);
586 ME_GetSelectionCharFormat(editor, &tmp);
587 ME_CopyToCFAny((CHARFORMAT2W *)lParam, &tmp);
590 case EM_SETPARAFORMAT:
591 ME_SetSelectionParaFormat(editor, (PARAFORMAT2 *)lParam);
592 ME_CommitUndo(editor);
594 case EM_GETPARAFORMAT:
595 ME_GetSelectionParaFormat(editor, (PARAFORMAT2 *)lParam);
600 ME_GetSelection(editor, &from, &to);
601 ME_InternalDeleteText(editor, from, to-from);
602 ME_CommitUndo(editor);
603 ME_UpdateRepaint(editor);
611 LPWSTR wszText = ME_ToUnicode(hWnd, (void *)lParam);
612 size_t len = lstrlenW(wszText);
613 TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText));
615 ME_GetSelection(editor, &from, &to);
616 ME_CursorFromCharOfs(editor, from, &c);
618 style = c.pRun->member.run.style;
619 ME_AddRefStyle(style); /* ME_GetInsertStyle has already done that */
622 style = ME_GetInsertStyle(editor, 0);
623 ME_InternalDeleteText(editor, from, to-from);
624 ME_InsertTextFromCursor(editor, 0, wszText, len, style);
625 ME_ReleaseStyle(style);
626 ME_EndToUnicode(hWnd, wszText);
627 /* drop temporary style if line end */
628 /* FIXME question: does abc\n mean: put abc, clear temp style, put \n? (would require a change) */
629 if (len>0 && wszText[len-1] == '\n')
630 ME_ClearTempStyle(editor);
632 ME_CommitUndo(editor);
634 ME_EmptyUndoStack(editor);
635 ME_UpdateRepaint(editor);
640 LPWSTR wszText = ME_ToUnicode(hWnd, (void *)lParam);
641 TRACE("WM_SETTEXT - %s\n", (char *)(wszText)); /* debugstr_w() */
642 ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor));
643 /* uses default style! */
644 ME_InsertTextFromCursor(editor, 0, wszText, -1, editor->pBuffer->pDefaultStyle);
645 ME_EndToUnicode(hWnd, wszText);
646 ME_CommitUndo(editor);
647 ME_EmptyUndoStack(editor);
648 ME_UpdateRepaint(editor);
658 if (!OpenClipboard(hWnd))
662 ME_GetSelection(editor, &from, &to);
663 pars = ME_CountParagraphsBetween(editor, from, to);
664 hData = GlobalAlloc(GMEM_MOVEABLE, sizeof(WCHAR)*(to-from+pars+1));
665 data = (WCHAR *)GlobalLock(hData);
666 ME_GetTextW(editor, data, from, to-from, TRUE);
668 SetClipboardData(CF_UNICODETEXT, hData);
672 ME_InternalDeleteText(editor, from, to-from);
673 ME_CommitUndo(editor);
674 ME_UpdateRepaint(editor);
678 case WM_GETTEXTLENGTH:
679 return ME_GetTextLength(editor);
682 TEXTRANGEW tr; /* W and A differ only by rng->lpstrText */
684 tr.chrg.cpMax = wParam-1;
685 tr.lpstrText = (WCHAR *)lParam;
686 return RichEditANSIWndProc(hWnd, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
691 TEXTRANGEW tr; /* W and A differ only by rng->lpstrText */
692 ME_GetSelection(editor, &from, &to);
693 tr.chrg.cpMin = from;
695 tr.lpstrText = (WCHAR *)lParam;
696 return RichEditANSIWndProc(hWnd, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
698 case EM_GETTEXTRANGE:
700 TEXTRANGEW *rng = (TEXTRANGEW *)lParam;
701 if (IsWindowUnicode(hWnd))
702 return ME_GetTextW(editor, rng->lpstrText, rng->chrg.cpMin, rng->chrg.cpMax-rng->chrg.cpMin, FALSE);
705 int nLen = rng->chrg.cpMax-rng->chrg.cpMin;
706 WCHAR *p = ALLOC_N_OBJ(WCHAR, nLen+1);
707 int nChars = ME_GetTextW(editor, p, rng->chrg.cpMin, nLen, FALSE);
708 /* FIXME this is a potential security hole (buffer overrun)
709 if you know more about wchar->mbyte conversion please explain
711 WideCharToMultiByte(CP_ACP, 0, p, nChars+1, (char *)rng->lpstrText, nLen+1, NULL, NULL);
715 return ME_GetTextW(editor, rng->lpstrText, rng->chrg.cpMin, rng->chrg.cpMax-rng->chrg.cpMin, FALSE);
718 ME_CommitUndo(editor);
719 /* ME_InsertTextFromCursor(editor, 0, (WCHAR *)L"x", 1, editor->pBuffer->pDefaultStyle); */
721 ME_MoveCaret(editor);
724 ME_DestroyEditor(editor);
725 SetWindowLongW(hWnd, 0, 0);
730 ME_LButtonDown(editor, (short)LOWORD(lParam), (short)HIWORD(lParam));
734 if (GetCapture() == hWnd)
735 ME_MouseMove(editor, (short)LOWORD(lParam), (short)HIWORD(lParam));
738 if (GetCapture() == hWnd)
742 hDC = BeginPaint(hWnd, &ps);
743 ME_PaintContent(editor, hDC, FALSE);
747 ME_ShowCaret(editor);
748 ME_SendOldNotify(editor, EN_SETFOCUS);
751 ME_HideCaret(editor);
752 ME_SendOldNotify(editor, EN_KILLFOCUS);
756 HDC hDC = (HDC)wParam;
758 COLORREF rgbBG = ME_GetBackColor(editor);
759 if (GetUpdateRect(hWnd,&rc,TRUE))
761 HBRUSH hbr = CreateSolidBrush(rgbBG);
762 FillRect(hDC, &rc, hbr);
768 TRACE("editor wnd command = %d\n", LOWORD(wParam));
771 if (ME_ArrowKey(editor, LOWORD(wParam), GetKeyState(VK_CONTROL)<0)) {
772 ME_CommitUndo(editor);
773 ME_EnsureVisible(editor, editor->pCursors[0].pRun);
775 ME_MoveCaret(editor);
779 if (GetKeyState(VK_CONTROL)<0)
781 if (LOWORD(wParam)=='W')
785 ME_GetSelectionCharFormat(editor, &chf);
786 ME_DumpStyleToBuf(&chf, buf);
787 MessageBoxA(NULL, buf, "Style dump", MB_OK);
789 if (LOWORD(wParam)=='Q')
791 ME_CheckCharOffsets(editor);
798 if (GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_READONLY) {
799 MessageBeep(MB_ICONERROR);
800 return 0; /* FIXME really 0 ? */
802 wstr = LOWORD(wParam);
803 if (((unsigned)wstr)>=' ' || wstr=='\r') {
804 /* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */
805 ME_Style *style = ME_GetInsertStyle(editor, 0);
806 ME_SaveTempStyle(editor);
807 ME_InsertTextFromCursor(editor, 0, &wstr, 1, style);
808 ME_ReleaseStyle(style);
809 ME_CommitUndo(editor);
810 ME_UpdateRepaint(editor);
816 si.cbSize = sizeof(SCROLLINFO);
817 si.fMask = SIF_PAGE|SIF_POS|SIF_RANGE|SIF_TRACKPOS;
818 GetScrollInfo(hWnd, SB_VERT, &si);
819 switch(LOWORD(wParam)) {
821 SetScrollPos(hWnd, SB_VERT, si.nTrackPos, FALSE);
822 ScrollWindow(hWnd, 0, si.nPos-si.nTrackPos, NULL, NULL);
823 /* InvalidateRect(hWnd, NULL, TRUE); */
831 ME_DisplayItem *tp = editor->pBuffer->pFirst;
834 if (tp->type == diParagraph)
836 tp->member.para.nFlags &= ~MEPF_WRAPPED;
837 tp = tp->member.para.next_para;
843 return DefWindowProcW(hWnd, msg, wParam, lParam);
845 case EM_GETOLEINTERFACE:
847 LPVOID *ppvObj = (LPVOID*) lParam;
848 TRACE("EM_GETOLEINTERFACE %p\n", ppvObj);
849 return CreateIRichEditOle(ppvObj);
853 return DefWindowProcW(hWnd, msg, wParam, lParam);
858 /******************************************************************
859 * RichEdit10ANSIWndProc (RICHED20.9)
861 LRESULT WINAPI RichEdit10ANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
863 /* FIXME: this is NOT the same as 2.0 version */
864 return RichEditANSIWndProc(hWnd, msg, wParam, lParam);
867 void ME_SendOldNotify(ME_TextEditor *editor, int nCode)
869 HWND hWnd = editor->hWnd;
870 SendMessageA(GetParent(hWnd), WM_COMMAND, (nCode<<16)|GetWindowLongW(hWnd, GWLP_ID), (LPARAM)hWnd);
873 int ME_CountParagraphsBetween(ME_TextEditor *editor, int from, int to)
875 ME_DisplayItem *item = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph);
878 while(item && item->member.para.next_para->member.para.nCharOfs <= from)
879 item = item->member.para.next_para;
882 while(item && item->member.para.next_para->member.para.nCharOfs <= to) {
883 item = item->member.para.next_para;
889 int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int nStart, int nChars, int bCRLF)
891 ME_DisplayItem *item = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph);
894 while(item && item->member.para.next_para->member.para.nCharOfs <= nStart)
895 item = ME_FindItemFwd(item, diParagraph);
900 nStart -= item->member.para.nCharOfs;
903 item = ME_FindItemFwd(item, diRun);
904 } while(item && (item->member.run.nCharOfs + ME_StrLen(item->member.run.strText) <= nStart));
907 nStart -= item->member.run.nCharOfs;
911 int nLen = ME_StrLen(item->member.run.strText) - nStart;
914 CopyMemory(buffer, item->member.run.strText->szData + nStart, sizeof(WCHAR)*nLen);
921 item = ME_FindItemFwd(item, diRun);
924 while(nChars && item)
926 int nLen = ME_StrLen(item->member.run.strText);
930 if (item->member.run.nFlags & MERF_ENDPARA)
940 CopyMemory(buffer, item->member.run.strText->szData, sizeof(WCHAR)*nLen);
950 item = ME_FindItemFwd(item, diRun);
956 static WCHAR wszClassName[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '2', '0', 'W', 0};
957 static WCHAR wszClassName50[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '5', '0', 'W', 0};
959 void ME_RegisterEditorClass(HINSTANCE hInstance)
965 wcW.style = CS_HREDRAW | CS_VREDRAW;
966 wcW.lpfnWndProc = RichEditANSIWndProc;
969 wcW.hInstance = NULL; /* hInstance would register DLL-local class */
971 wcW.hCursor = LoadCursorW(NULL, MAKEINTRESOURCEW(IDC_IBEAM));
972 wcW.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
973 wcW.lpszMenuName = NULL;
974 wcW.lpszClassName = wszClassName;
975 bResult = RegisterClassW(&wcW);
977 wcW.lpszClassName = wszClassName50;
978 bResult = RegisterClassW(&wcW);
981 wcA.style = CS_HREDRAW | CS_VREDRAW;
982 wcA.lpfnWndProc = RichEditANSIWndProc;
985 wcA.hInstance = NULL; /* hInstance would register DLL-local class */
987 wcA.hCursor = LoadCursorW(NULL, MAKEINTRESOURCEW(IDC_IBEAM));
988 wcA.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
989 wcA.lpszMenuName = NULL;
990 wcA.lpszClassName = "RichEdit20A";
991 bResult = RegisterClassA(&wcA);
993 wcA.lpszClassName = "RichEdit50A";
994 bResult = RegisterClassA(&wcA);
998 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
1003 case DLL_PROCESS_ATTACH:
1004 DisableThreadLibraryCalls(hinstDLL);
1005 me_heap = HeapCreate (0, 0x10000, 0);
1006 ME_RegisterEditorClass(hinstDLL);
1009 case DLL_PROCESS_DETACH:
1010 UnregisterClassW(wszClassName, 0);
1011 UnregisterClassW(wszClassName50, 0);
1012 UnregisterClassA("RichEdit20A", 0);
1013 UnregisterClassA("RichEdit50A", 0);
1014 HeapDestroy (me_heap);
1021 /******************************************************************
1022 * CreateTextServices (RICHED20.4)
1024 * FIXME should be ITextHost instead of void*
1026 HRESULT WINAPI CreateTextServices(IUnknown *punkOuter, void *pITextHost,
1030 /* FIXME should support aggregation */
1032 return CLASS_E_NOAGGREGATION;
1034 return E_FAIL; /* E_NOTIMPL isn't allowed by MSDN */
1037 /******************************************************************
1038 * REExtendedRegisterClass (RICHED20.8)
1040 * FIXME undocumented
1042 void WINAPI REExtendedRegisterClass(void)