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
105 + EM_STREAMIN (can't fall back to text when the RTF isn't really RTF)
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):
169 * - messages/styles/notifications listed above
171 * - add remaining CHARFORMAT/PARAFORMAT fields
172 * - right/center align should strip spaces from the beginning
173 * - more advanced navigation (Ctrl-arrows)
175 * - pictures/OLE objects (not just smiling faces that lack API support ;-) )
176 * - COM interface (looks like a major pain in the TODO list)
177 * - calculate heights of pictures (half-done)
178 * - horizontal scrolling (not even started)
179 * - hysteresis during wrapping (related to scrollbars appearing/disappearing)
181 * - how to implement EM_FORMATRANGE and EM_DISPLAYBAND ? (Mission Impossible)
182 * - italic caret with italic fonts
184 * - most notifications aren't sent at all (the most important ones are)
185 * - when should EN_SELCHANGE be sent after text change ? (before/after EN_UPDATE?)
186 * - WM_SETTEXT may use wrong style (but I'm 80% sure it's OK)
187 * - EM_GETCHARFORMAT with SCF_SELECTION may not behave 100% like in original (but very close)
189 * Bugs that are probably fixed, but not so easy to verify:
190 * - EN_UPDATE/EN_CHANGE are handled very incorrectly (should be OK now)
191 * - undo for ME_JoinParagraphs doesn't store paragraph format ? (it does)
192 * - check/fix artificial EOL logic (bCursorAtEnd, hardly logical)
193 * - caret shouldn't be displayed when selection isn't empty
194 * - check refcounting in style management functions (looks perfect now, but no bugs is suspicious)
195 * - undo for setting default format (done, might be buggy)
196 * - styles might be not released properly (looks like they work like charm, but who knows?
204 #define NO_SHLWAPI_STREAM
209 WINE_DEFAULT_DEBUG_CHANNEL(richedit
);
212 HANDLE me_heap
= NULL
;
214 ME_TextBuffer
*ME_MakeText() {
216 ME_TextBuffer
*buf
= ALLOC_OBJ(ME_TextBuffer
);
218 ME_DisplayItem
*p1
= ME_MakeDI(diTextStart
);
219 ME_DisplayItem
*p2
= ME_MakeDI(diTextEnd
);
225 p1
->member
.para
.next_para
= p2
;
226 p2
->member
.para
.prev_para
= p1
;
227 p2
->member
.para
.nCharOfs
= 0;
231 buf
->pCharStyle
= NULL
;
237 static LRESULT
ME_StreamInText(ME_TextEditor
*editor
, DWORD dwFormat
, ME_InStream
*stream
, ME_Style
*style
)
239 WCHAR wszText
[STREAMIN_BUFFER_SIZE
+1];
242 TRACE("%08lx %p\n", dwFormat
, stream
);
249 ME_StreamInFill(stream
);
250 if (stream
->editstream
->dwError
)
256 if (!(dwFormat
& SF_UNICODE
))
258 /* FIXME? this is doomed to fail on true MBCS like UTF-8, luckily they're unlikely to be used as CP_ACP */
259 nWideChars
= MultiByteToWideChar(CP_ACP
, 0, stream
->buffer
, stream
->dwSize
, wszText
, STREAMIN_BUFFER_SIZE
);
264 nWideChars
= stream
->dwSize
>> 1;
265 pText
= (WCHAR
*)stream
->buffer
;
268 ME_InsertTextFromCursor(editor
, 0, pText
, nWideChars
, style
);
269 if (stream
->dwSize
< STREAMIN_BUFFER_SIZE
)
272 ME_CommitUndo(editor
);
277 void ME_RTFCharAttrHook(RTF_Info
*info
)
280 fmt
.cbSize
= sizeof(fmt
);
283 switch(info
->rtfMinor
)
286 /* FIXME add more flags once they're implemented */
287 fmt
.dwMask
= CFM_BOLD
| CFM_ITALIC
| CFM_UNDERLINE
| CFM_STRIKEOUT
| CFM_COLOR
| CFM_BACKCOLOR
| CFM_SIZE
| CFM_WEIGHT
;
288 fmt
.dwEffects
= CFE_AUTOCOLOR
| CFE_AUTOBACKCOLOR
;
289 fmt
.yHeight
= 12*20; /* 12pt */
293 fmt
.dwMask
= CFM_BOLD
;
294 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
297 fmt
.dwMask
= CFM_ITALIC
;
298 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
301 fmt
.dwMask
= CFM_UNDERLINE
;
302 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
305 fmt
.dwMask
= CFM_STRIKEOUT
;
306 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
309 fmt
.dwMask
= CFM_BACKCOLOR
;
311 if (info
->rtfParam
== 0)
312 fmt
.dwEffects
= CFE_AUTOBACKCOLOR
;
313 else if (info
->rtfParam
!= rtfNoParam
)
315 RTFColor
*c
= RTFGetColor(info
, info
->rtfParam
);
316 fmt
.crTextColor
= (c
->rtfCBlue
<<16)|(c
->rtfCGreen
<<8)|(c
->rtfCRed
);
320 fmt
.dwMask
= CFM_COLOR
;
322 if (info
->rtfParam
== 0)
323 fmt
.dwEffects
= CFE_AUTOCOLOR
;
324 else if (info
->rtfParam
!= rtfNoParam
)
326 RTFColor
*c
= RTFGetColor(info
, info
->rtfParam
);
327 fmt
.crTextColor
= (c
->rtfCBlue
<<16)|(c
->rtfCGreen
<<8)|(c
->rtfCRed
);
331 if (info
->rtfParam
!= rtfNoParam
)
333 RTFFont
*f
= RTFGetFont(info
, info
->rtfParam
);
336 MultiByteToWideChar(CP_ACP
, 0, f
->rtfFName
, -1, fmt
.szFaceName
, sizeof(fmt
.szFaceName
)/sizeof(WCHAR
));
337 fmt
.szFaceName
[sizeof(fmt
.szFaceName
)/sizeof(WCHAR
)-1] = '\0';
338 fmt
.bCharSet
= f
->rtfFCharSet
;
339 fmt
.dwMask
= CFM_FACE
| CFM_CHARSET
;
344 fmt
.dwMask
= CFM_SIZE
;
345 if (info
->rtfParam
!= rtfNoParam
)
346 fmt
.yHeight
= info
->rtfParam
*10;
351 RTFFlushOutputBuffer(info
);
352 /* FIXME too slow ? how come ? */
353 style2
= ME_ApplyStyle(info
->style
, &fmt
);
354 ME_ReleaseStyle(info
->style
);
355 info
->style
= style2
;
359 /* FIXME this function doesn't get any information about context of the RTF tag, which is very bad,
360 the same tags mean different things in different contexts */
361 void ME_RTFParAttrHook(RTF_Info
*info
)
364 fmt
.cbSize
= sizeof(fmt
);
367 switch(info
->rtfMinor
)
369 case rtfParDef
: /* I'm not 100% sure what does it do, but I guess it restores default paragraph attributes */
370 fmt
.dwMask
= PFM_ALIGNMENT
| PFM_TABSTOPS
| PFM_OFFSET
| PFM_STARTINDENT
;
371 fmt
.wAlignment
= PFA_LEFT
;
373 fmt
.dxOffset
= fmt
.dxStartIndent
= 0;
376 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
377 fmt
.dwMask
= PFM_STARTINDENT
;
378 fmt
.dxStartIndent
= info
->rtfParam
+ fmt
.dxOffset
;
383 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
384 first
= fmt
.dxStartIndent
;
385 left
= info
->rtfParam
;
386 fmt
.dwMask
= PFM_STARTINDENT
|PFM_OFFSET
;
387 fmt
.dxStartIndent
= first
+ left
;
388 fmt
.dxOffset
= -first
;
392 fmt
.dwMask
= PFM_RIGHTINDENT
;
393 fmt
.dxRightIndent
= info
->rtfParam
;
397 fmt
.dwMask
= PFM_ALIGNMENT
;
398 fmt
.wAlignment
= PFA_LEFT
;
401 fmt
.dwMask
= PFM_ALIGNMENT
;
402 fmt
.wAlignment
= PFA_RIGHT
;
405 fmt
.dwMask
= PFM_ALIGNMENT
;
406 fmt
.wAlignment
= PFA_CENTER
;
409 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
410 if (!(fmt
.dwMask
& PFM_TABSTOPS
))
412 fmt
.dwMask
|= PFM_TABSTOPS
;
415 if (fmt
.cTabCount
< MAX_TAB_STOPS
)
416 fmt
.rgxTabs
[fmt
.cTabCount
++] = info
->rtfParam
;
420 RTFFlushOutputBuffer(info
);
421 /* FIXME too slow ? how come ?*/
422 ME_SetSelectionParaFormat(info
->editor
, &fmt
);
426 void ME_RTFReadHook(RTF_Info
*info
) {
427 switch(info
->rtfClass
)
430 switch(info
->rtfMajor
)
433 if (info
->stackTop
< maxStack
) {
434 memcpy(&info
->stack
[info
->stackTop
].fmt
, &info
->style
->fmt
, sizeof(CHARFORMAT2W
));
435 info
->stack
[info
->stackTop
].codePage
= info
->codePage
;
436 info
->stack
[info
->stackTop
].unicodeLength
= info
->unicodeLength
;
443 RTFFlushOutputBuffer(info
);
445 /* FIXME too slow ? how come ? */
446 s
= ME_ApplyStyle(info
->style
, &info
->stack
[info
->stackTop
].fmt
);
447 ME_ReleaseStyle(info
->style
);
449 info
->codePage
= info
->stack
[info
->stackTop
].codePage
;
450 info
->unicodeLength
= info
->stack
[info
->stackTop
].unicodeLength
;
456 switch(info
->rtfMajor
)
459 ME_RTFCharAttrHook(info
);
462 ME_RTFParAttrHook(info
);
470 ME_StreamInFill(ME_InStream
*stream
)
472 stream
->editstream
->dwError
= stream
->editstream
->pfnCallback(stream
->editstream
->dwCookie
,
474 sizeof(stream
->buffer
),
479 static LRESULT
ME_StreamIn(ME_TextEditor
*editor
, DWORD format
, EDITSTREAM
*stream
)
483 int from
, to
, to2
, nUndoMode
;
485 int nEventMask
= editor
->nEventMask
;
486 ME_InStream inStream
;
488 TRACE("%p %p\n", stream
, editor
->hWnd
);
489 editor
->nEventMask
= 0;
491 ME_GetSelection(editor
, &from
, &to
);
492 if (format
& SFF_SELECTION
) {
493 style
= ME_GetSelectionInsertStyle(editor
);
495 ME_InternalDeleteText(editor
, from
, to
-from
);
498 style
= editor
->pBuffer
->pDefaultStyle
;
499 ME_AddRefStyle(style
);
500 SendMessageA(editor
->hWnd
, EM_SETSEL
, 0, 0);
501 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
));
503 ME_ClearTempStyle(editor
);
504 /* FIXME restore default paragraph formatting ! */
507 nUndoMode
= editor
->nUndoMode
;
508 editor
->nUndoMode
= umIgnore
;
510 inStream
.editstream
= stream
;
511 inStream
.editstream
->dwError
= 0;
517 /* Check if it's really RTF, and if it is not, use plain text */
518 ME_StreamInFill(&inStream
);
519 if (!inStream
.editstream
->dwError
)
521 if (strncmp(inStream
.buffer
, "{\\rtf1", 6) && strncmp(inStream
.buffer
, "{\\urtf", 6))
529 if (!inStream
.editstream
->dwError
)
531 if (format
& SF_RTF
) {
532 /* setup the RTF parser */
533 memset(&parser
, 0, sizeof parser
);
534 RTFSetEditStream(&parser
, &inStream
);
535 parser
.rtfFormat
= format
&(SF_TEXT
|SF_RTF
);
536 parser
.hwndEdit
= editor
->hWnd
;
537 parser
.editor
= editor
;
538 parser
.style
= style
;
541 RTFSetReadHook(&parser
, ME_RTFReadHook
);
546 RTFFlushOutputBuffer(&parser
);
549 style
= parser
.style
;
551 else if (format
& SF_TEXT
)
552 ME_StreamInText(editor
, format
, &inStream
, style
);
554 ERR("EM_STREAMIN without SF_TEXT or SF_RTF\n");
555 ME_GetSelection(editor
, &to
, &to2
);
556 /* put the cursor at the top */
557 if (!(format
& SFF_SELECTION
))
558 SendMessageA(editor
->hWnd
, EM_SETSEL
, 0, 0);
561 /* FIXME where to put cursor now ? */
565 editor
->nUndoMode
= nUndoMode
;
566 pUI
= ME_AddUndoItem(editor
, diUndoDeleteRun
, NULL
);
567 TRACE("from %d to %d\n", from
, to
);
568 if (pUI
&& from
< to
)
573 ME_CommitUndo(editor
);
574 ME_ReleaseStyle(style
);
575 editor
->nEventMask
= nEventMask
;
576 InvalidateRect(editor
->hWnd
, NULL
, TRUE
);
577 ME_UpdateRepaint(editor
);
578 if (!(format
& SFF_SELECTION
)) {
579 ME_ClearTempStyle(editor
);
581 ME_MoveCaret(editor
);
582 ME_SendSelChange(editor
);
589 ME_FindItemAtOffset(ME_TextEditor
*editor
, ME_DIType nItemType
, int nOffset
, int *nItemOffset
)
591 ME_DisplayItem
*item
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
593 while (item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= nOffset
)
594 item
= ME_FindItemFwd(item
, diParagraph
);
599 nOffset
-= item
->member
.para
.nCharOfs
;
600 if (nItemType
== diParagraph
) {
602 *nItemOffset
= nOffset
;
607 item
= ME_FindItemFwd(item
, diRun
);
608 } while (item
&& (item
->member
.run
.nCharOfs
+ ME_StrLen(item
->member
.run
.strText
) <= nOffset
));
610 nOffset
-= item
->member
.run
.nCharOfs
;
612 *nItemOffset
= nOffset
;
618 ME_TextEditor
*ME_MakeEditor(HWND hWnd
) {
619 ME_TextEditor
*ed
= ALLOC_OBJ(ME_TextEditor
);
623 ed
->pBuffer
= ME_MakeText();
625 ME_MakeFirstParagraph(hDC
, ed
->pBuffer
);
626 ReleaseDC(hWnd
, hDC
);
627 ed
->bCaretShown
= FALSE
;
629 ed
->pCursors
= ALLOC_N_OBJ(ME_Cursor
, ed
->nCursors
);
630 ed
->pCursors
[0].pRun
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diRun
);
631 ed
->pCursors
[0].nOffset
= 0;
632 ed
->pCursors
[1].pRun
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diRun
);
633 ed
->pCursors
[1].nOffset
= 0;
634 ed
->nLastTotalLength
= ed
->nTotalLength
= 0;
637 ed
->rgbBackColor
= -1;
638 ed
->bCaretAtEnd
= FALSE
;
641 ed
->pUndoStack
= ed
->pRedoStack
= NULL
;
642 ed
->nUndoMode
= umAddToUndo
;
644 ed
->nLastSelStart
= ed
->nLastSelEnd
= 0;
646 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
648 ed
->pFontCache
[i
].nRefs
= 0;
649 ed
->pFontCache
[i
].nAge
= 0;
650 ed
->pFontCache
[i
].hFont
= NULL
;
652 ME_CheckCharOffsets(ed
);
656 typedef struct tagME_GlobalDestStruct
660 } ME_GlobalDestStruct
;
662 static DWORD CALLBACK
ME_AppendToHGLOBAL(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
664 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
668 nMaxSize
= GlobalSize(pData
->hData
);
669 if (pData
->nLength
+cb
+1 >= cb
)
671 /* round up to 2^17 */
672 int nNewSize
= (((nMaxSize
+cb
+1)|0x1FFFF)+1) & 0xFFFE0000;
673 pData
->hData
= GlobalReAlloc(pData
->hData
, nNewSize
, 0);
675 pDest
= (BYTE
*)GlobalLock(pData
->hData
);
676 memcpy(pDest
+ pData
->nLength
, lpBuff
, cb
);
677 pData
->nLength
+= cb
;
678 pDest
[pData
->nLength
] = '\0';
679 GlobalUnlock(pData
->hData
);
685 static DWORD CALLBACK
ME_ReadFromHGLOBALUnicode(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
687 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
692 pDest
= (WORD
*)lpBuff
;
693 pSrc
= (WORD
*)GlobalLock(pData
->hData
);
694 for (i
= 0; i
<cb
&& pSrc
[pData
->nLength
+i
]; i
++) {
695 pDest
[i
] = pSrc
[pData
->nLength
+i
];
699 GlobalUnlock(pData
->hData
);
703 static DWORD CALLBACK
ME_ReadFromHGLOBALRTF(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
705 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
710 pSrc
= (BYTE
*)GlobalLock(pData
->hData
);
711 for (i
= 0; i
<cb
&& pSrc
[pData
->nLength
+i
]; i
++) {
712 pDest
[i
] = pSrc
[pData
->nLength
+i
];
716 GlobalUnlock(pData
->hData
);
720 void ME_DestroyEditor(ME_TextEditor
*editor
)
722 ME_DisplayItem
*pFirst
= editor
->pBuffer
->pFirst
;
723 ME_DisplayItem
*p
= pFirst
, *pNext
= NULL
;
726 ME_ClearTempStyle(editor
);
727 ME_EmptyUndoStack(editor
);
730 ME_DestroyDisplayItem(p
);
733 ME_ReleaseStyle(editor
->pBuffer
->pDefaultStyle
);
734 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
736 if (editor
->pFontCache
[i
].hFont
)
737 DeleteObject(editor
->pFontCache
[i
].hFont
);
743 #define UNSUPPORTED_MSG(e) \
745 FIXME(#e ": stub\n"); \
746 return DefWindowProcW(hWnd, msg, wParam, lParam);
748 /******************************************************************
749 * RichEditANSIWndProc (RICHED20.10)
751 LRESULT WINAPI
RichEditANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
) {
755 ME_TextEditor
*editor
= (ME_TextEditor
*)GetWindowLongW(hWnd
, 0);
756 TRACE("msg %d %08x %08lx\n", msg
, wParam
, lParam
);
759 UNSUPPORTED_MSG(EM_AUTOURLDETECT
)
760 UNSUPPORTED_MSG(EM_CHARFROMPOS
)
761 UNSUPPORTED_MSG(EM_DISPLAYBAND
)
762 UNSUPPORTED_MSG(EM_EXLIMITTEXT
)
763 UNSUPPORTED_MSG(EM_EXLINEFROMCHAR
)
764 UNSUPPORTED_MSG(EM_FINDTEXT
)
765 UNSUPPORTED_MSG(EM_FINDTEXTEX
)
766 UNSUPPORTED_MSG(EM_FINDWORDBREAK
)
767 UNSUPPORTED_MSG(EM_FMTLINES
)
768 UNSUPPORTED_MSG(EM_FORMATRANGE
)
769 UNSUPPORTED_MSG(EM_GETFIRSTVISIBLELINE
)
770 UNSUPPORTED_MSG(EM_GETIMECOMPMODE
)
771 /* UNSUPPORTED_MSG(EM_GETIMESTATUS) missing in Wine headers */
772 UNSUPPORTED_MSG(EM_GETLANGOPTIONS
)
773 UNSUPPORTED_MSG(EM_GETLIMITTEXT
)
774 UNSUPPORTED_MSG(EM_GETLINE
)
775 UNSUPPORTED_MSG(EM_GETLINECOUNT
)
776 /* UNSUPPORTED_MSG(EM_GETOLEINTERFACE) separate stub */
777 UNSUPPORTED_MSG(EM_GETOPTIONS
)
778 UNSUPPORTED_MSG(EM_GETRECT
)
779 UNSUPPORTED_MSG(EM_GETREDONAME
)
780 UNSUPPORTED_MSG(EM_GETTEXTMODE
)
781 UNSUPPORTED_MSG(EM_GETUNDONAME
)
782 UNSUPPORTED_MSG(EM_GETWORDBREAKPROC
)
783 UNSUPPORTED_MSG(EM_GETWORDBREAKPROCEX
)
784 UNSUPPORTED_MSG(EM_HIDESELECTION
)
785 UNSUPPORTED_MSG(EM_LIMITTEXT
) /* also known as EM_SETLIMITTEXT */
786 UNSUPPORTED_MSG(EM_LINEFROMCHAR
)
787 UNSUPPORTED_MSG(EM_LINEINDEX
)
788 UNSUPPORTED_MSG(EM_LINELENGTH
)
789 UNSUPPORTED_MSG(EM_LINESCROLL
)
790 UNSUPPORTED_MSG(EM_PASTESPECIAL
)
791 /* UNSUPPORTED_MSG(EM_POSFROMCHARS) missing in Wine headers */
792 UNSUPPORTED_MSG(EM_REQUESTRESIZE
)
793 UNSUPPORTED_MSG(EM_SCROLL
)
794 UNSUPPORTED_MSG(EM_SCROLLCARET
)
795 UNSUPPORTED_MSG(EM_SELECTIONTYPE
)
796 UNSUPPORTED_MSG(EM_SETLANGOPTIONS
)
797 UNSUPPORTED_MSG(EM_SETOLECALLBACK
)
798 UNSUPPORTED_MSG(EM_SETOPTIONS
)
799 UNSUPPORTED_MSG(EM_SETRECT
)
800 UNSUPPORTED_MSG(EM_SETRECTNP
)
801 UNSUPPORTED_MSG(EM_SETTARGETDEVICE
)
802 UNSUPPORTED_MSG(EM_SETTEXTMODE
)
803 UNSUPPORTED_MSG(EM_SETUNDOLIMIT
)
804 UNSUPPORTED_MSG(EM_SETWORDBREAKPROC
)
805 UNSUPPORTED_MSG(EM_SETWORDBREAKPROCEX
)
806 UNSUPPORTED_MSG(WM_SETFONT
)
807 UNSUPPORTED_MSG(WM_STYLECHANGING
)
808 UNSUPPORTED_MSG(WM_STYLECHANGED
)
809 /* UNSUPPORTED_MSG(WM_UNICHAR) FIXME missing in Wine headers */
811 /* Messages specific to Richedit controls */
814 return ME_StreamIn(editor
, wParam
, (EDITSTREAM
*)lParam
);
816 return ME_StreamOut(editor
, wParam
, (EDITSTREAM
*)lParam
);
819 UINT code
= DLGC_WANTCHARS
|DLGC_WANTARROWS
;
820 if (GetWindowLongW(hWnd
, GWL_STYLE
)&ES_WANTRETURN
)
821 code
|= 0; /* FIXME what can we do here ? ask for messages and censor them ? */
826 CREATESTRUCTW
*pcs
= (CREATESTRUCTW
*)lParam
;
827 editor
= ME_MakeEditor(hWnd
);
828 SetWindowLongW(hWnd
, 0, (long)editor
);
829 pcs
= 0; /* ignore */
832 case EM_EMPTYUNDOBUFFER
:
833 ME_EmptyUndoStack(editor
);
837 ME_GetSelection(editor
, (int *)wParam
, (int *)lParam
);
838 if (!((wParam
|lParam
) & 0xFFFF0000))
839 return (lParam
<<16)|wParam
;
844 CHARRANGE
*pRange
= (CHARRANGE
*)lParam
;
845 ME_GetSelection(editor
, (int *)&pRange
->cpMin
, (int *)&pRange
->cpMax
);
849 return editor
->pUndoStack
!= NULL
;
851 return editor
->pRedoStack
!= NULL
;
860 ME_SetSelection(editor
, wParam
, lParam
);
862 ME_SendSelChange(editor
);
867 CHARRANGE
*pRange
= (CHARRANGE
*)lParam
;
868 ME_SetSelection(editor
, pRange
->cpMin
, pRange
->cpMax
);
871 ME_SendSelChange(editor
);
874 case EM_SETBKGNDCOLOR
:
876 LRESULT lColor
= ME_GetBackColor(editor
);
878 editor
->rgbBackColor
= -1;
880 editor
->rgbBackColor
= lParam
;
881 InvalidateRect(hWnd
, NULL
, TRUE
);
886 return editor
->nModifyStep
== 0 ? 0 : 1;
890 editor
->nModifyStep
= 0x80000000;
892 editor
->nModifyStep
= 0;
898 long nStyle
= GetWindowLongW(hWnd
, GWL_STYLE
);
900 nStyle
|= ES_READONLY
;
902 nStyle
&= ~ES_READONLY
;
903 SetWindowLongW(hWnd
, GWL_STYLE
, nStyle
);
907 case EM_SETEVENTMASK
:
908 editor
->nEventMask
= lParam
;
910 case EM_GETEVENTMASK
:
911 return editor
->nEventMask
;
912 case EM_SETCHARFORMAT
:
914 CHARFORMAT2W buf
, *p
;
915 BOOL bRepaint
= TRUE
;
916 p
= ME_ToCF2W(&buf
, (CHARFORMAT2W
*)lParam
);
918 ME_SetDefaultCharFormat(editor
, p
);
919 else if (wParam
== (SCF_WORD
| SCF_SELECTION
))
920 FIXME("word selection not supported\n");
921 else if (wParam
== SCF_ALL
)
922 ME_SetCharFormat(editor
, 0, ME_GetTextLength(editor
), p
);
925 ME_GetSelection(editor
, &from
, &to
);
926 bRepaint
= (from
!= to
);
927 ME_SetSelectionCharFormat(editor
, p
);
929 ME_CommitUndo(editor
);
931 ME_UpdateRepaint(editor
);
934 case EM_GETCHARFORMAT
:
937 tmp
.cbSize
= sizeof(tmp
);
939 ME_GetDefaultCharFormat(editor
, &tmp
);
941 ME_GetSelectionCharFormat(editor
, &tmp
);
942 ME_CopyToCFAny((CHARFORMAT2W
*)lParam
, &tmp
);
945 case EM_SETPARAFORMAT
:
946 ME_SetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
947 ME_UpdateRepaint(editor
);
948 ME_CommitUndo(editor
);
950 case EM_GETPARAFORMAT
:
951 ME_GetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
956 ME_GetSelection(editor
, &from
, &to
);
957 ME_InternalDeleteText(editor
, from
, to
-from
);
958 ME_CommitUndo(editor
);
959 ME_UpdateRepaint(editor
);
966 LPWSTR wszText
= ME_ToUnicode(hWnd
, (void *)lParam
);
967 size_t len
= lstrlenW(wszText
);
968 TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText
));
970 ME_GetSelection(editor
, &from
, &to
);
971 style
= ME_GetSelectionInsertStyle(editor
);
972 ME_InternalDeleteText(editor
, from
, to
-from
);
973 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, style
);
974 ME_ReleaseStyle(style
);
975 ME_EndToUnicode(hWnd
, wszText
);
976 /* drop temporary style if line end */
977 /* FIXME question: does abc\n mean: put abc, clear temp style, put \n? (would require a change) */
978 if (len
>0 && wszText
[len
-1] == '\n')
979 ME_ClearTempStyle(editor
);
981 ME_CommitUndo(editor
);
983 ME_EmptyUndoStack(editor
);
984 ME_UpdateRepaint(editor
);
989 LPWSTR wszText
= ME_ToUnicode(hWnd
, (void *)lParam
);
990 TRACE("WM_SETTEXT - %s\n", (char *)(wszText
)); /* debugstr_w() */
991 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
));
992 /* uses default style! */
993 ME_InsertTextFromCursor(editor
, 0, wszText
, -1, editor
->pBuffer
->pDefaultStyle
);
994 ME_EndToUnicode(hWnd
, wszText
);
995 ME_CommitUndo(editor
);
996 ME_EmptyUndoStack(editor
);
997 ME_UpdateRepaint(editor
);
1002 UINT nRTFFormat
= RegisterClipboardFormatA("Rich Text Format");
1003 if (IsClipboardFormatAvailable(nRTFFormat
))
1005 if (IsClipboardFormatAvailable(CF_UNICODETEXT
))
1013 ME_GlobalDestStruct gds
;
1014 UINT nRTFFormat
= RegisterClipboardFormatA("Rich Text Format");
1017 if (IsClipboardFormatAvailable(nRTFFormat
))
1018 cf
= nRTFFormat
, dwFormat
= SF_RTF
;
1019 else if (IsClipboardFormatAvailable(CF_UNICODETEXT
))
1020 cf
= CF_UNICODETEXT
, dwFormat
= SF_TEXT
|SF_UNICODE
;
1024 if (!OpenClipboard(hWnd
))
1026 gds
.hData
= GetClipboardData(cf
);
1028 es
.dwCookie
= (DWORD
)&gds
;
1029 es
.pfnCallback
= dwFormat
== SF_RTF
? ME_ReadFromHGLOBALRTF
: ME_ReadFromHGLOBALUnicode
;
1030 SendMessageW(hWnd
, EM_STREAMIN
, dwFormat
|SFF_SELECTION
, (LPARAM
)&es
);
1042 ME_GlobalDestStruct gds
;
1044 if (!OpenClipboard(hWnd
))
1048 ME_GetSelection(editor
, &from
, &to
);
1049 pars
= ME_CountParagraphsBetween(editor
, from
, to
);
1050 hData
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(WCHAR
)*(to
-from
+pars
+1));
1051 data
= (WCHAR
*)GlobalLock(hData
);
1052 ME_GetTextW(editor
, data
, from
, to
-from
, TRUE
);
1053 GlobalUnlock(hData
);
1055 gds
.hData
= GlobalAlloc(GMEM_MOVEABLE
, 0);
1057 es
.dwCookie
= (DWORD
)&gds
;
1058 es
.pfnCallback
= ME_AppendToHGLOBAL
;
1059 SendMessageW(hWnd
, EM_STREAMOUT
, SFF_SELECTION
|SF_RTF
, (LPARAM
)&es
);
1060 GlobalReAlloc(gds
.hData
, gds
.nLength
+1, 0);
1062 SetClipboardData(CF_UNICODETEXT
, hData
);
1063 SetClipboardData(RegisterClipboardFormatA("Rich Text Format"), gds
.hData
);
1068 ME_InternalDeleteText(editor
, from
, to
-from
);
1069 ME_CommitUndo(editor
);
1070 ME_UpdateRepaint(editor
);
1074 case WM_GETTEXTLENGTH
:
1075 return ME_GetTextLength(editor
);
1078 TEXTRANGEW tr
; /* W and A differ only by rng->lpstrText */
1080 tr
.chrg
.cpMax
= wParam
-1;
1081 tr
.lpstrText
= (WCHAR
*)lParam
;
1082 return RichEditANSIWndProc(hWnd
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
);
1087 TEXTRANGEW tr
; /* W and A differ only by rng->lpstrText */
1088 ME_GetSelection(editor
, &from
, &to
);
1089 tr
.chrg
.cpMin
= from
;
1091 tr
.lpstrText
= (WCHAR
*)lParam
;
1092 return RichEditANSIWndProc(hWnd
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
);
1094 case EM_GETTEXTRANGE
:
1096 TEXTRANGEW
*rng
= (TEXTRANGEW
*)lParam
;
1097 if (IsWindowUnicode(hWnd
))
1098 return ME_GetTextW(editor
, rng
->lpstrText
, rng
->chrg
.cpMin
, rng
->chrg
.cpMax
-rng
->chrg
.cpMin
, FALSE
);
1101 int nLen
= rng
->chrg
.cpMax
-rng
->chrg
.cpMin
;
1102 WCHAR
*p
= ALLOC_N_OBJ(WCHAR
, nLen
+1);
1103 int nChars
= ME_GetTextW(editor
, p
, rng
->chrg
.cpMin
, nLen
, FALSE
);
1104 /* FIXME this is a potential security hole (buffer overrun)
1105 if you know more about wchar->mbyte conversion please explain
1107 WideCharToMultiByte(CP_ACP
, 0, p
, nChars
+1, (char *)rng
->lpstrText
, nLen
+1, NULL
, NULL
);
1111 return ME_GetTextW(editor
, rng
->lpstrText
, rng
->chrg
.cpMin
, rng
->chrg
.cpMax
-rng
->chrg
.cpMin
, FALSE
);
1114 ME_CommitUndo(editor
);
1115 ME_WrapMarkedParagraphs(editor
);
1116 ME_MoveCaret(editor
);
1119 ME_DestroyEditor(editor
);
1120 SetWindowLongW(hWnd
, 0, 0);
1122 case WM_LBUTTONDOWN
:
1124 ME_LButtonDown(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
1128 if (GetCapture() == hWnd
)
1129 ME_MouseMove(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
1132 if (GetCapture() == hWnd
)
1136 hDC
= BeginPaint(hWnd
, &ps
);
1137 ME_PaintContent(editor
, hDC
, FALSE
, &ps
.rcPaint
);
1138 EndPaint(hWnd
, &ps
);
1141 ME_ShowCaret(editor
);
1142 ME_SendOldNotify(editor
, EN_SETFOCUS
);
1145 ME_HideCaret(editor
);
1146 ME_SendOldNotify(editor
, EN_KILLFOCUS
);
1150 HDC hDC
= (HDC
)wParam
;
1152 COLORREF rgbBG
= ME_GetBackColor(editor
);
1153 if (GetUpdateRect(hWnd
,&rc
,TRUE
))
1155 HBRUSH hbr
= CreateSolidBrush(rgbBG
);
1156 FillRect(hDC
, &rc
, hbr
);
1162 TRACE("editor wnd command = %d\n", LOWORD(wParam
));
1165 if (ME_ArrowKey(editor
, LOWORD(wParam
), GetKeyState(VK_CONTROL
)<0)) {
1166 ME_CommitUndo(editor
);
1167 ME_EnsureVisible(editor
, editor
->pCursors
[0].pRun
);
1169 ME_MoveCaret(editor
);
1173 if (GetKeyState(VK_CONTROL
)<0)
1175 if (LOWORD(wParam
)=='W')
1179 ME_GetSelectionCharFormat(editor
, &chf
);
1180 ME_DumpStyleToBuf(&chf
, buf
);
1181 MessageBoxA(NULL
, buf
, "Style dump", MB_OK
);
1183 if (LOWORD(wParam
)=='Q')
1185 ME_CheckCharOffsets(editor
);
1192 if (GetWindowLongW(editor
->hWnd
, GWL_STYLE
) & ES_READONLY
) {
1193 MessageBeep(MB_ICONERROR
);
1194 return 0; /* FIXME really 0 ? */
1196 wstr
= LOWORD(wParam
);
1197 if (((unsigned)wstr
)>=' ' || wstr
=='\r' || wstr
=='\t') {
1198 /* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */
1199 ME_Style
*style
= ME_GetInsertStyle(editor
, 0);
1200 ME_SaveTempStyle(editor
);
1201 ME_InsertTextFromCursor(editor
, 0, &wstr
, 1, style
);
1202 ME_ReleaseStyle(style
);
1203 ME_CommitUndo(editor
);
1204 ME_UpdateRepaint(editor
);
1210 int nPos
= editor
->nScrollPosY
;
1211 si
.cbSize
= sizeof(SCROLLINFO
);
1212 si
.fMask
= SIF_PAGE
|SIF_POS
|SIF_RANGE
|SIF_TRACKPOS
;
1213 GetScrollInfo(hWnd
, SB_VERT
, &si
);
1214 switch(LOWORD(wParam
)) {
1216 nPos
-= 24; /* FIXME follow the original */
1217 if (nPos
<0) nPos
= 0;
1221 int nEnd
= editor
->nTotalLength
- editor
->sizeWindow
.cy
;
1222 nPos
+= 24; /* FIXME follow the original */
1223 if (nPos
>=nEnd
) nPos
= nEnd
;
1227 nPos
-= editor
->sizeWindow
.cy
;
1228 if (nPos
<0) nPos
= 0;
1231 nPos
+= editor
->sizeWindow
.cy
;
1232 if (nPos
>=editor
->nTotalLength
) nPos
= editor
->nTotalLength
-1;
1235 case SB_THUMBPOSITION
:
1236 nPos
= si
.nTrackPos
;
1239 if (nPos
!= editor
->nScrollPosY
) {
1240 ScrollWindow(hWnd
, 0, editor
->nScrollPosY
-nPos
, NULL
, NULL
);
1241 editor
->nScrollPosY
= nPos
;
1242 SetScrollPos(hWnd
, SB_VERT
, nPos
, TRUE
);
1249 int gcWheelDelta
= 0, nPos
= editor
->nScrollPosY
;
1250 UINT pulScrollLines
;
1252 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
1253 gcWheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
1254 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
1255 nPos
+= pulScrollLines
* (gcWheelDelta
/ WHEEL_DELTA
) * 8;
1256 if(nPos
>=editor
->nTotalLength
)
1257 nPos
= editor
->nTotalLength
- 1;
1260 if (nPos
!= editor
->nScrollPosY
) {
1261 ScrollWindow(hWnd
, 0, editor
->nScrollPosY
-nPos
, NULL
, NULL
);
1262 editor
->nScrollPosY
= nPos
;
1263 SetScrollPos(hWnd
, SB_VERT
, nPos
, TRUE
);
1270 ME_MarkAllForWrapping(editor
);
1271 ME_WrapMarkedParagraphs(editor
);
1272 ME_UpdateScrollBar(editor
);
1274 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
1276 case EM_GETOLEINTERFACE
:
1278 LPVOID
*ppvObj
= (LPVOID
*) lParam
;
1279 FIXME("EM_GETOLEINTERFACE %p: stub\n", ppvObj
);
1280 return CreateIRichEditOle(ppvObj
);
1284 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
1289 /******************************************************************
1290 * RichEdit10ANSIWndProc (RICHED20.9)
1292 LRESULT WINAPI
RichEdit10ANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1294 /* FIXME: this is NOT the same as 2.0 version */
1295 return RichEditANSIWndProc(hWnd
, msg
, wParam
, lParam
);
1298 void ME_SendOldNotify(ME_TextEditor
*editor
, int nCode
)
1300 HWND hWnd
= editor
->hWnd
;
1301 SendMessageA(GetParent(hWnd
), WM_COMMAND
, (nCode
<<16)|GetWindowLongW(hWnd
, GWLP_ID
), (LPARAM
)hWnd
);
1304 int ME_CountParagraphsBetween(ME_TextEditor
*editor
, int from
, int to
)
1306 ME_DisplayItem
*item
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
1309 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= from
)
1310 item
= item
->member
.para
.next_para
;
1313 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= to
) {
1314 item
= item
->member
.para
.next_para
;
1321 int ME_GetTextW(ME_TextEditor
*editor
, WCHAR
*buffer
, int nStart
, int nChars
, int bCRLF
)
1323 ME_DisplayItem
*item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
1334 int nLen
= ME_StrLen(item
->member
.run
.strText
) - nStart
;
1337 CopyMemory(buffer
, item
->member
.run
.strText
->szData
+ nStart
, sizeof(WCHAR
)*nLen
);
1344 item
= ME_FindItemFwd(item
, diRun
);
1347 while(nChars
&& item
)
1349 int nLen
= ME_StrLen(item
->member
.run
.strText
);
1353 if (item
->member
.run
.nFlags
& MERF_ENDPARA
)
1363 CopyMemory(buffer
, item
->member
.run
.strText
->szData
, sizeof(WCHAR
)*nLen
);
1373 item
= ME_FindItemFwd(item
, diRun
);
1379 static WCHAR wszClassName
[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '2', '0', 'W', 0};
1380 static WCHAR wszClassName50
[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '5', '0', 'W', 0};
1382 void ME_RegisterEditorClass(HINSTANCE hInstance
)
1388 wcW
.style
= CS_HREDRAW
| CS_VREDRAW
;
1389 wcW
.lpfnWndProc
= RichEditANSIWndProc
;
1392 wcW
.hInstance
= NULL
; /* hInstance would register DLL-local class */
1394 wcW
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
1395 wcW
.hbrBackground
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
1396 wcW
.lpszMenuName
= NULL
;
1397 wcW
.lpszClassName
= wszClassName
;
1398 bResult
= RegisterClassW(&wcW
);
1400 wcW
.lpszClassName
= wszClassName50
;
1401 bResult
= RegisterClassW(&wcW
);
1404 wcA
.style
= CS_HREDRAW
| CS_VREDRAW
;
1405 wcA
.lpfnWndProc
= RichEditANSIWndProc
;
1408 wcA
.hInstance
= NULL
; /* hInstance would register DLL-local class */
1410 wcA
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
1411 wcA
.hbrBackground
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
1412 wcA
.lpszMenuName
= NULL
;
1413 wcA
.lpszClassName
= "RichEdit20A";
1414 bResult
= RegisterClassA(&wcA
);
1416 wcA
.lpszClassName
= "RichEdit50A";
1417 bResult
= RegisterClassA(&wcA
);
1421 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
1426 case DLL_PROCESS_ATTACH
:
1427 DisableThreadLibraryCalls(hinstDLL
);
1428 me_heap
= HeapCreate (0, 0x10000, 0);
1429 ME_RegisterEditorClass(hinstDLL
);
1432 case DLL_PROCESS_DETACH
:
1433 UnregisterClassW(wszClassName
, 0);
1434 UnregisterClassW(wszClassName50
, 0);
1435 UnregisterClassA("RichEdit20A", 0);
1436 UnregisterClassA("RichEdit50A", 0);
1437 HeapDestroy (me_heap
);
1444 /******************************************************************
1445 * CreateTextServices (RICHED20.4)
1447 * FIXME should be ITextHost instead of void*
1449 HRESULT WINAPI
CreateTextServices(IUnknown
*punkOuter
, void *pITextHost
,
1453 /* FIXME should support aggregation */
1455 return CLASS_E_NOAGGREGATION
;
1457 return E_FAIL
; /* E_NOTIMPL isn't allowed by MSDN */
1460 /******************************************************************
1461 * REExtendedRegisterClass (RICHED20.8)
1463 * FIXME undocumented
1465 void WINAPI
REExtendedRegisterClass(void)