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 ME_TextBuffer
*ME_MakeText() {
221 ME_TextBuffer
*buf
= ALLOC_OBJ(ME_TextBuffer
);
223 ME_DisplayItem
*p1
= ME_MakeDI(diTextStart
);
224 ME_DisplayItem
*p2
= ME_MakeDI(diTextEnd
);
230 p1
->member
.para
.next_para
= p2
;
231 p2
->member
.para
.prev_para
= p1
;
232 p2
->member
.para
.nCharOfs
= 0;
236 buf
->pCharStyle
= NULL
;
241 #define STREAMIN_BUFFER_SIZE 4096 /* M$ compatibility */
243 static LRESULT
ME_StreamInText(ME_TextEditor
*editor
, DWORD dwFormat
, EDITSTREAM
*stream
, ME_Style
*style
)
245 BYTE buffer
[STREAMIN_BUFFER_SIZE
+1];
246 WCHAR wszText
[STREAMIN_BUFFER_SIZE
+1];
248 TRACE("%08lx %p\n", dwFormat
, stream
);
252 long nDataSize
= 0, nWideChars
= 0;
253 stream
->dwError
= stream
->pfnCallback(stream
->dwCookie
,
254 (dwFormat
& SF_UNICODE
? (BYTE
*)wszText
: buffer
),
255 STREAMIN_BUFFER_SIZE
, &nDataSize
);
262 if (!(dwFormat
& SF_UNICODE
))
264 /* FIXME? this is doomed to fail on true MBCS like UTF-8, luckily they're unlikely to be used as CP_ACP */
265 nWideChars
= MultiByteToWideChar(CP_ACP
, 0, buffer
, nDataSize
, wszText
, STREAMIN_BUFFER_SIZE
);
268 nWideChars
= nDataSize
>>1;
269 ME_InsertTextFromCursor(editor
, 0, wszText
, nWideChars
, style
);
270 if (nDataSize
<STREAMIN_BUFFER_SIZE
)
273 ME_CommitUndo(editor
);
277 static LRESULT
ME_StreamIn(ME_TextEditor
*editor
, DWORD format
, EDITSTREAM
*stream
)
282 FIXME("%08lx %p\n", format
, stream
);
283 TRACE("%p %p\n", stream
, editor
->hWnd
);
285 if (format
& SFF_SELECTION
) {
286 style
= ME_GetSelectionInsertStyle(editor
);
287 SendMessageW(editor
->hWnd
, WM_CLEAR
, 0, 0);
290 style
= editor
->pBuffer
->pDefaultStyle
;
291 ME_AddRefStyle(style
);
292 SendMessageA(editor
->hWnd
, EM_SETSEL
, 0, 0);
293 SetWindowTextA(editor
->hWnd
, "");
294 ME_ClearTempStyle(editor
);
297 if (format
& SF_RTF
) {
298 /* setup the RTF parser */
299 memset(&parser
, 0, sizeof parser
);
300 RTFSetEditStream(&parser
, stream
);
301 parser
.rtfFormat
= format
&(SF_TEXT
|SF_RTF
);
302 parser
.hwndEdit
= editor
->hWnd
;
309 RTFFlushOutputBuffer(&parser
);
311 else if (format
& SF_TEXT
)
312 ME_StreamInText(editor
, format
, stream
, style
);
314 ERR("EM_STREAMIN without SF_TEXT or SF_RTF\n");
315 /* put the cursor at the top */
316 if (!(format
& SFF_SELECTION
))
317 SendMessageA(editor
->hWnd
, EM_SETSEL
, 0, 0);
320 /* FIXME where to put cursor now ? */
322 ME_ReleaseStyle(style
);
327 ME_TextEditor
*ME_MakeEditor(HWND hWnd
) {
328 ME_TextEditor
*ed
= ALLOC_OBJ(ME_TextEditor
);
332 ed
->pBuffer
= ME_MakeText();
334 ME_MakeFirstParagraph(hDC
, ed
->pBuffer
);
335 ReleaseDC(hWnd
, hDC
);
336 ed
->bCaretShown
= FALSE
;
338 ed
->pCursors
= ALLOC_N_OBJ(ME_Cursor
, ed
->nCursors
);
339 ed
->pCursors
[0].pRun
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diRun
);
340 ed
->pCursors
[0].nOffset
= 0;
341 ed
->pCursors
[1].pRun
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diRun
);
342 ed
->pCursors
[1].nOffset
= 0;
343 ed
->nTotalLength
= 0;
347 ed
->rgbBackColor
= -1;
348 ed
->bCaretAtEnd
= FALSE
;
351 ed
->pUndoStack
= ed
->pRedoStack
= NULL
;
352 ed
->nUndoMode
= umAddToUndo
;
354 ed
->nLastSelStart
= ed
->nLastSelEnd
= 0;
355 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
357 ed
->pFontCache
[i
].nRefs
= 0;
358 ed
->pFontCache
[i
].nAge
= 0;
359 ed
->pFontCache
[i
].hFont
= NULL
;
361 ME_CheckCharOffsets(ed
);
365 void ME_DestroyEditor(ME_TextEditor
*editor
)
367 ME_DisplayItem
*pFirst
= editor
->pBuffer
->pFirst
;
368 ME_DisplayItem
*p
= pFirst
, *pNext
= NULL
;
371 ME_ClearTempStyle(editor
);
372 ME_EmptyUndoStack(editor
);
375 ME_DestroyDisplayItem(p
);
378 ME_ReleaseStyle(editor
->pBuffer
->pDefaultStyle
);
379 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
381 if (editor
->pFontCache
[i
].hFont
)
382 DeleteObject(editor
->pFontCache
[i
].hFont
);
388 #define UNSUPPORTED_MSG(e) \
390 FIXME(#e ": stub\n"); \
391 return DefWindowProcW(hWnd, msg, wParam, lParam);
393 /******************************************************************
394 * RichEditANSIWndProc (RICHED20.10)
396 LRESULT WINAPI
RichEditANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
) {
400 ME_TextEditor
*editor
= (ME_TextEditor
*)GetWindowLongW(hWnd
, 0);
403 UNSUPPORTED_MSG(EM_AUTOURLDETECT
)
404 UNSUPPORTED_MSG(EM_CANPASTE
)
405 UNSUPPORTED_MSG(EM_CHARFROMPOS
)
406 UNSUPPORTED_MSG(EM_DISPLAYBAND
)
407 UNSUPPORTED_MSG(EM_EXLIMITTEXT
)
408 UNSUPPORTED_MSG(EM_EXLINEFROMCHAR
)
409 UNSUPPORTED_MSG(EM_FINDTEXT
)
410 UNSUPPORTED_MSG(EM_FINDTEXTEX
)
411 UNSUPPORTED_MSG(EM_FINDWORDBREAK
)
412 UNSUPPORTED_MSG(EM_FMTLINES
)
413 UNSUPPORTED_MSG(EM_FORMATRANGE
)
414 UNSUPPORTED_MSG(EM_GETFIRSTVISIBLELINE
)
415 UNSUPPORTED_MSG(EM_GETIMECOMPMODE
)
416 /* UNSUPPORTED_MSG(EM_GETIMESTATUS) missing in Wine headers */
417 UNSUPPORTED_MSG(EM_GETLANGOPTIONS
)
418 UNSUPPORTED_MSG(EM_GETLIMITTEXT
)
419 UNSUPPORTED_MSG(EM_GETLINE
)
420 UNSUPPORTED_MSG(EM_GETLINECOUNT
)
421 /* UNSUPPORTED_MSG(EM_GETOLEINTERFACE) separate stub */
422 UNSUPPORTED_MSG(EM_GETOPTIONS
)
423 UNSUPPORTED_MSG(EM_GETRECT
)
424 UNSUPPORTED_MSG(EM_GETREDONAME
)
425 UNSUPPORTED_MSG(EM_GETTEXTMODE
)
426 UNSUPPORTED_MSG(EM_GETUNDONAME
)
427 UNSUPPORTED_MSG(EM_GETWORDBREAKPROC
)
428 UNSUPPORTED_MSG(EM_GETWORDBREAKPROCEX
)
429 UNSUPPORTED_MSG(EM_HIDESELECTION
)
430 UNSUPPORTED_MSG(EM_LIMITTEXT
) /* also known as EM_SETLIMITTEXT */
431 UNSUPPORTED_MSG(EM_LINEFROMCHAR
)
432 UNSUPPORTED_MSG(EM_LINEINDEX
)
433 UNSUPPORTED_MSG(EM_LINELENGTH
)
434 UNSUPPORTED_MSG(EM_LINESCROLL
)
435 UNSUPPORTED_MSG(EM_PASTESPECIAL
)
436 /* UNSUPPORTED_MSG(EM_POSFROMCHARS) missing in Wine headers */
437 UNSUPPORTED_MSG(EM_REQUESTRESIZE
)
438 UNSUPPORTED_MSG(EM_SCROLL
)
439 UNSUPPORTED_MSG(EM_SCROLLCARET
)
440 UNSUPPORTED_MSG(EM_SELECTIONTYPE
)
441 UNSUPPORTED_MSG(EM_SETLANGOPTIONS
)
442 UNSUPPORTED_MSG(EM_SETOLECALLBACK
)
443 UNSUPPORTED_MSG(EM_SETOPTIONS
)
444 UNSUPPORTED_MSG(EM_SETRECT
)
445 UNSUPPORTED_MSG(EM_SETRECTNP
)
446 UNSUPPORTED_MSG(EM_SETTARGETDEVICE
)
447 UNSUPPORTED_MSG(EM_SETTEXTMODE
)
448 UNSUPPORTED_MSG(EM_SETUNDOLIMIT
)
449 UNSUPPORTED_MSG(EM_SETWORDBREAKPROC
)
450 UNSUPPORTED_MSG(EM_SETWORDBREAKPROCEX
)
451 UNSUPPORTED_MSG(EM_STREAMOUT
)
452 UNSUPPORTED_MSG(WM_SETFONT
)
453 UNSUPPORTED_MSG(WM_PASTE
)
454 UNSUPPORTED_MSG(WM_STYLECHANGING
)
455 UNSUPPORTED_MSG(WM_STYLECHANGED
)
456 /* UNSUPPORTED_MSG(WM_UNICHAR) FIXME missing in Wine headers */
458 /* Messages specific to Richedit controls */
461 return ME_StreamIn(editor
, wParam
, (EDITSTREAM
*)lParam
);
464 UINT code
= DLGC_WANTCHARS
|DLGC_WANTARROWS
;
465 if (GetWindowLongW(hWnd
, GWL_STYLE
)&ES_WANTRETURN
)
466 code
|= 0; /* FIXME what can we do here ? ask for messages and censor them ? */
471 CREATESTRUCTW
*pcs
= (CREATESTRUCTW
*)lParam
;
472 editor
= ME_MakeEditor(hWnd
);
473 SetWindowLongW(hWnd
, 0, (long)editor
);
474 pcs
= 0; /* ignore */
477 case EM_EMPTYUNDOBUFFER
:
478 ME_EmptyUndoStack(editor
);
482 ME_GetSelection(editor
, (int *)wParam
, (int *)lParam
);
483 if (!((wParam
|lParam
) & 0xFFFF0000))
484 return (lParam
<<16)|wParam
;
489 CHARRANGE
*pRange
= (CHARRANGE
*)lParam
;
490 ME_GetSelection(editor
, (int *)&pRange
->cpMin
, (int *)&pRange
->cpMax
);
494 return editor
->pUndoStack
!= NULL
;
496 return editor
->pRedoStack
!= NULL
;
505 ME_SetSelection(editor
, wParam
, lParam
);
507 ME_SendSelChange(editor
);
512 CHARRANGE
*pRange
= (CHARRANGE
*)lParam
;
513 ME_SetSelection(editor
, pRange
->cpMin
, pRange
->cpMax
);
516 ME_SendSelChange(editor
);
519 case EM_SETBKGNDCOLOR
:
521 LRESULT lColor
= ME_GetBackColor(editor
);
523 editor
->rgbBackColor
= -1;
525 editor
->rgbBackColor
= lParam
;
526 InvalidateRect(hWnd
, NULL
, TRUE
);
531 return editor
->nModifyStep
== 0 ? 0 : 1;
535 editor
->nModifyStep
= 0x80000000;
537 editor
->nModifyStep
= 0;
543 long nStyle
= GetWindowLongW(hWnd
, GWL_STYLE
);
545 nStyle
|= ES_READONLY
;
547 nStyle
&= ~ES_READONLY
;
548 SetWindowLongW(hWnd
, GWL_STYLE
, nStyle
);
552 case EM_SETEVENTMASK
:
553 editor
->nEventMask
= lParam
;
555 case EM_GETEVENTMASK
:
556 return editor
->nEventMask
;
557 case EM_SETCHARFORMAT
:
559 CHARFORMAT2W buf
, *p
;
560 p
= ME_ToCF2W(&buf
, (CHARFORMAT2W
*)lParam
);
562 ME_SetDefaultCharFormat(editor
, p
);
563 else if (wParam
== (SCF_WORD
| SCF_SELECTION
))
564 FIXME("word selection not supported\n");
565 else if (wParam
== SCF_ALL
)
566 ME_SetCharFormat(editor
, 0, ME_GetTextLength(editor
), p
);
568 ME_SetSelectionCharFormat(editor
, p
);
569 ME_CommitUndo(editor
);
570 ME_UpdateRepaint(editor
);
573 case EM_GETCHARFORMAT
:
576 tmp
.cbSize
= sizeof(tmp
);
578 ME_GetDefaultCharFormat(editor
, &tmp
);
580 ME_GetSelectionCharFormat(editor
, &tmp
);
581 ME_CopyToCFAny((CHARFORMAT2W
*)lParam
, &tmp
);
584 case EM_SETPARAFORMAT
:
585 ME_SetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
586 ME_CommitUndo(editor
);
588 case EM_GETPARAFORMAT
:
589 ME_GetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
594 ME_GetSelection(editor
, &from
, &to
);
595 ME_InternalDeleteText(editor
, from
, to
-from
);
596 ME_CommitUndo(editor
);
597 ME_UpdateRepaint(editor
);
604 LPWSTR wszText
= ME_ToUnicode(hWnd
, (void *)lParam
);
605 size_t len
= lstrlenW(wszText
);
606 TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText
));
608 ME_GetSelection(editor
, &from
, &to
);
609 style
= ME_GetSelectionInsertStyle(editor
);
610 ME_InternalDeleteText(editor
, from
, to
-from
);
611 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, style
);
612 ME_ReleaseStyle(style
);
613 ME_EndToUnicode(hWnd
, wszText
);
614 /* drop temporary style if line end */
615 /* FIXME question: does abc\n mean: put abc, clear temp style, put \n? (would require a change) */
616 if (len
>0 && wszText
[len
-1] == '\n')
617 ME_ClearTempStyle(editor
);
619 ME_CommitUndo(editor
);
621 ME_EmptyUndoStack(editor
);
622 ME_UpdateRepaint(editor
);
627 LPWSTR wszText
= ME_ToUnicode(hWnd
, (void *)lParam
);
628 TRACE("WM_SETTEXT - %s\n", (char *)(wszText
)); /* debugstr_w() */
629 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
));
630 /* uses default style! */
631 ME_InsertTextFromCursor(editor
, 0, wszText
, -1, editor
->pBuffer
->pDefaultStyle
);
632 ME_EndToUnicode(hWnd
, wszText
);
633 ME_CommitUndo(editor
);
634 ME_EmptyUndoStack(editor
);
635 ME_UpdateRepaint(editor
);
645 if (!OpenClipboard(hWnd
))
649 ME_GetSelection(editor
, &from
, &to
);
650 pars
= ME_CountParagraphsBetween(editor
, from
, to
);
651 hData
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(WCHAR
)*(to
-from
+pars
+1));
652 data
= (WCHAR
*)GlobalLock(hData
);
653 ME_GetTextW(editor
, data
, from
, to
-from
, TRUE
);
655 SetClipboardData(CF_UNICODETEXT
, hData
);
659 ME_InternalDeleteText(editor
, from
, to
-from
);
660 ME_CommitUndo(editor
);
661 ME_UpdateRepaint(editor
);
665 case WM_GETTEXTLENGTH
:
666 return ME_GetTextLength(editor
);
669 TEXTRANGEW tr
; /* W and A differ only by rng->lpstrText */
671 tr
.chrg
.cpMax
= wParam
-1;
672 tr
.lpstrText
= (WCHAR
*)lParam
;
673 return RichEditANSIWndProc(hWnd
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
);
678 TEXTRANGEW tr
; /* W and A differ only by rng->lpstrText */
679 ME_GetSelection(editor
, &from
, &to
);
680 tr
.chrg
.cpMin
= from
;
682 tr
.lpstrText
= (WCHAR
*)lParam
;
683 return RichEditANSIWndProc(hWnd
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
);
685 case EM_GETTEXTRANGE
:
687 TEXTRANGEW
*rng
= (TEXTRANGEW
*)lParam
;
688 if (IsWindowUnicode(hWnd
))
689 return ME_GetTextW(editor
, rng
->lpstrText
, rng
->chrg
.cpMin
, rng
->chrg
.cpMax
-rng
->chrg
.cpMin
, FALSE
);
692 int nLen
= rng
->chrg
.cpMax
-rng
->chrg
.cpMin
;
693 WCHAR
*p
= ALLOC_N_OBJ(WCHAR
, nLen
+1);
694 int nChars
= ME_GetTextW(editor
, p
, rng
->chrg
.cpMin
, nLen
, FALSE
);
695 /* FIXME this is a potential security hole (buffer overrun)
696 if you know more about wchar->mbyte conversion please explain
698 WideCharToMultiByte(CP_ACP
, 0, p
, nChars
+1, (char *)rng
->lpstrText
, nLen
+1, NULL
, NULL
);
702 return ME_GetTextW(editor
, rng
->lpstrText
, rng
->chrg
.cpMin
, rng
->chrg
.cpMax
-rng
->chrg
.cpMin
, FALSE
);
705 ME_CommitUndo(editor
);
706 /* ME_InsertTextFromCursor(editor, 0, (WCHAR *)L"x", 1, editor->pBuffer->pDefaultStyle); */
707 ME_WrapMarkedParagraphs(editor
);
708 ME_MoveCaret(editor
);
711 ME_DestroyEditor(editor
);
712 SetWindowLongW(hWnd
, 0, 0);
717 ME_LButtonDown(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
721 if (GetCapture() == hWnd
)
722 ME_MouseMove(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
725 if (GetCapture() == hWnd
)
729 hDC
= BeginPaint(hWnd
, &ps
);
730 ME_PaintContent(editor
, hDC
, FALSE
);
734 ME_ShowCaret(editor
);
735 ME_SendOldNotify(editor
, EN_SETFOCUS
);
738 ME_HideCaret(editor
);
739 ME_SendOldNotify(editor
, EN_KILLFOCUS
);
743 HDC hDC
= (HDC
)wParam
;
745 COLORREF rgbBG
= ME_GetBackColor(editor
);
746 if (GetUpdateRect(hWnd
,&rc
,TRUE
))
748 HBRUSH hbr
= CreateSolidBrush(rgbBG
);
749 FillRect(hDC
, &rc
, hbr
);
755 TRACE("editor wnd command = %d\n", LOWORD(wParam
));
758 if (ME_ArrowKey(editor
, LOWORD(wParam
), GetKeyState(VK_CONTROL
)<0)) {
759 ME_CommitUndo(editor
);
760 ME_EnsureVisible(editor
, editor
->pCursors
[0].pRun
);
762 ME_MoveCaret(editor
);
766 if (GetKeyState(VK_CONTROL
)<0)
768 if (LOWORD(wParam
)=='W')
772 ME_GetSelectionCharFormat(editor
, &chf
);
773 ME_DumpStyleToBuf(&chf
, buf
);
774 MessageBoxA(NULL
, buf
, "Style dump", MB_OK
);
776 if (LOWORD(wParam
)=='Q')
778 ME_CheckCharOffsets(editor
);
785 if (GetWindowLongW(editor
->hWnd
, GWL_STYLE
) & ES_READONLY
) {
786 MessageBeep(MB_ICONERROR
);
787 return 0; /* FIXME really 0 ? */
789 wstr
= LOWORD(wParam
);
790 if (((unsigned)wstr
)>=' ' || wstr
=='\r') {
791 /* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */
792 ME_Style
*style
= ME_GetInsertStyle(editor
, 0);
793 ME_SaveTempStyle(editor
);
794 ME_InsertTextFromCursor(editor
, 0, &wstr
, 1, style
);
795 ME_ReleaseStyle(style
);
796 ME_CommitUndo(editor
);
797 ME_UpdateRepaint(editor
);
803 si
.cbSize
= sizeof(SCROLLINFO
);
804 si
.fMask
= SIF_PAGE
|SIF_POS
|SIF_RANGE
|SIF_TRACKPOS
;
805 GetScrollInfo(hWnd
, SB_VERT
, &si
);
806 switch(LOWORD(wParam
)) {
808 SetScrollPos(hWnd
, SB_VERT
, si
.nTrackPos
, FALSE
);
809 ScrollWindow(hWnd
, 0, si
.nPos
-si
.nTrackPos
, NULL
, NULL
);
810 /* InvalidateRect(hWnd, NULL, TRUE); */
818 ME_MarkAllForWrapping(editor
);
820 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
822 case EM_GETOLEINTERFACE
:
824 LPVOID
*ppvObj
= (LPVOID
*) lParam
;
825 TRACE("EM_GETOLEINTERFACE %p\n", ppvObj
);
826 return CreateIRichEditOle(ppvObj
);
830 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
835 /******************************************************************
836 * RichEdit10ANSIWndProc (RICHED20.9)
838 LRESULT WINAPI
RichEdit10ANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
840 /* FIXME: this is NOT the same as 2.0 version */
841 return RichEditANSIWndProc(hWnd
, msg
, wParam
, lParam
);
844 void ME_SendOldNotify(ME_TextEditor
*editor
, int nCode
)
846 HWND hWnd
= editor
->hWnd
;
847 SendMessageA(GetParent(hWnd
), WM_COMMAND
, (nCode
<<16)|GetWindowLongW(hWnd
, GWLP_ID
), (LPARAM
)hWnd
);
850 int ME_CountParagraphsBetween(ME_TextEditor
*editor
, int from
, int to
)
852 ME_DisplayItem
*item
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
855 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= from
)
856 item
= item
->member
.para
.next_para
;
859 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= to
) {
860 item
= item
->member
.para
.next_para
;
866 int ME_GetTextW(ME_TextEditor
*editor
, WCHAR
*buffer
, int nStart
, int nChars
, int bCRLF
)
868 ME_DisplayItem
*item
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
871 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= nStart
)
872 item
= ME_FindItemFwd(item
, diParagraph
);
877 nStart
-= item
->member
.para
.nCharOfs
;
880 item
= ME_FindItemFwd(item
, diRun
);
881 } while(item
&& (item
->member
.run
.nCharOfs
+ ME_StrLen(item
->member
.run
.strText
) <= nStart
));
884 nStart
-= item
->member
.run
.nCharOfs
;
888 int nLen
= ME_StrLen(item
->member
.run
.strText
) - nStart
;
891 CopyMemory(buffer
, item
->member
.run
.strText
->szData
+ nStart
, sizeof(WCHAR
)*nLen
);
898 item
= ME_FindItemFwd(item
, diRun
);
901 while(nChars
&& item
)
903 int nLen
= ME_StrLen(item
->member
.run
.strText
);
907 if (item
->member
.run
.nFlags
& MERF_ENDPARA
)
917 CopyMemory(buffer
, item
->member
.run
.strText
->szData
, sizeof(WCHAR
)*nLen
);
927 item
= ME_FindItemFwd(item
, diRun
);
933 static WCHAR wszClassName
[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '2', '0', 'W', 0};
934 static WCHAR wszClassName50
[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '5', '0', 'W', 0};
936 void ME_RegisterEditorClass(HINSTANCE hInstance
)
942 wcW
.style
= CS_HREDRAW
| CS_VREDRAW
;
943 wcW
.lpfnWndProc
= RichEditANSIWndProc
;
946 wcW
.hInstance
= NULL
; /* hInstance would register DLL-local class */
948 wcW
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
949 wcW
.hbrBackground
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
950 wcW
.lpszMenuName
= NULL
;
951 wcW
.lpszClassName
= wszClassName
;
952 bResult
= RegisterClassW(&wcW
);
954 wcW
.lpszClassName
= wszClassName50
;
955 bResult
= RegisterClassW(&wcW
);
958 wcA
.style
= CS_HREDRAW
| CS_VREDRAW
;
959 wcA
.lpfnWndProc
= RichEditANSIWndProc
;
962 wcA
.hInstance
= NULL
; /* hInstance would register DLL-local class */
964 wcA
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
965 wcA
.hbrBackground
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
966 wcA
.lpszMenuName
= NULL
;
967 wcA
.lpszClassName
= "RichEdit20A";
968 bResult
= RegisterClassA(&wcA
);
970 wcA
.lpszClassName
= "RichEdit50A";
971 bResult
= RegisterClassA(&wcA
);
975 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
980 case DLL_PROCESS_ATTACH
:
981 DisableThreadLibraryCalls(hinstDLL
);
982 me_heap
= HeapCreate (0, 0x10000, 0);
983 ME_RegisterEditorClass(hinstDLL
);
986 case DLL_PROCESS_DETACH
:
987 UnregisterClassW(wszClassName
, 0);
988 UnregisterClassW(wszClassName50
, 0);
989 UnregisterClassA("RichEdit20A", 0);
990 UnregisterClassA("RichEdit50A", 0);
991 HeapDestroy (me_heap
);
998 /******************************************************************
999 * CreateTextServices (RICHED20.4)
1001 * FIXME should be ITextHost instead of void*
1003 HRESULT WINAPI
CreateTextServices(IUnknown
*punkOuter
, void *pITextHost
,
1007 /* FIXME should support aggregation */
1009 return CLASS_E_NOAGGREGATION
;
1011 return E_FAIL
; /* E_NOTIMPL isn't allowed by MSDN */
1014 /******************************************************************
1015 * REExtendedRegisterClass (RICHED20.8)
1017 * FIXME undocumented
1019 void WINAPI
REExtendedRegisterClass(void)