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_GETAUTOURLDETECT 2.0
42 - EM_GETBIDIOPTIONS 3.0
43 - EM_GETCHARFORMAT (partly done)
46 - EM_GETFIRSTVISIBLELINE
47 - EM_GETIMECOLOR 1.0asian
48 - EM_GETIMECOMPMODE 2.0
49 - EM_GETIMEOPTIONS 1.0asian
51 - EM_GETLANGOPTIONS 2.0
54 - EM_GETLINECOUNT returns number of rows, not of paragraphs
59 - EM_GETPASSWORDCHAR 2.0
60 - EM_GETPUNCTUATION 1.0asian
64 + EM_GETSELTEXT (ANSI&Unicode)
68 + EM_GETTEXTLENGTHEX (GTL_PRECISE unimplemented)
70 ? + EM_GETTEXTRANGE (ANSI&Unicode)
71 - EM_GETTYPOGRAPHYOPTIONS 3.0
74 - EM_GETWORDBREAKPROCEX
75 - EM_GETWORDWRAPMODE 1.0asian
87 + EM_REPLACESEL (proper style?) ANSI&Unicode
91 - EM_SETBIDIOPTIONS 3.0
93 - EM_SETCHARFORMAT (partly done, no ANSI)
95 + EM_SETEVENTMASK (few notifications supported)
97 - EM_SETIMECOLOR 1.0asian
98 - EM_SETIMEOPTIONS 1.0asian
99 - EM_SETLANGOPTIONS 2.0
101 + EM_SETMODIFY (not sure if implementation is correct)
106 - EM_SETPASSWORDCHAR 2.0
107 - EM_SETPUNCTUATION 1.0asian
108 + EM_SETREADONLY no beep on modification attempt
110 - EM_SETRECTNP (EM_SETRECT without repainting) - not supported in RICHEDIT
112 - EM_SETSCROLLPOS 3.0
117 - EM_SETTYPOGRAPHYOPTIONS 3.0
118 - EM_SETUNDOLIMIT 2.0
119 - EM_SETWORDBREAKPROC
120 - EM_SETWORDBREAKPROCEX
121 - EM_SETWORDWRAPMODE 1.0asian
123 - EM_SHOWSCROLLBAR 2.0
124 - EM_STOPGROUPTYPING 2.0
132 + WM_GETDLGCODE (the current implementation is incomplete)
133 + WM_GETTEXT (ANSI&Unicode)
134 + WM_GETTEXTLENGTH (ANSI version sucks)
137 + WM_SETTEXT (resets undo stack !) (proper style?) ANSI&Unicode
139 - WM_STYLECHANGED (things like read-only flag)
144 * EN_CHANGE (sent from the wrong place)
161 * EN_UPDATE (sent from the wrong place)
169 - ES_DISABLENOSCROLL (scrollbar is always visible)
170 - ES_EX_NOCALLOLEINIT
172 - ES_MULTILINE (currently single line controls aren't supported)
174 - ES_READONLY (I'm not sure if beeping is the proper behaviour)
180 - ES_WANTRETURN (don't know how to do WM_GETDLGCODE part)
187 * RICHED20 TODO (incomplete):
189 * - messages/styles/notifications listed above
191 * - add remaining CHARFORMAT/PARAFORMAT fields
192 * - right/center align should strip spaces from the beginning
193 * - more advanced navigation (Ctrl-arrows)
195 * - pictures/OLE objects (not just smiling faces that lack API support ;-) )
196 * - COM interface (looks like a major pain in the TODO list)
197 * - calculate heights of pictures (half-done)
198 * - horizontal scrolling (not even started)
199 * - hysteresis during wrapping (related to scrollbars appearing/disappearing)
201 * - how to implement EM_FORMATRANGE and EM_DISPLAYBAND ? (Mission Impossible)
202 * - italic caret with italic fonts
204 * - most notifications aren't sent at all (the most important ones are)
205 * - when should EN_SELCHANGE be sent after text change ? (before/after EN_UPDATE?)
206 * - WM_SETTEXT may use wrong style (but I'm 80% sure it's OK)
207 * - EM_GETCHARFORMAT with SCF_SELECTION may not behave 100% like in original (but very close)
209 * Bugs that are probably fixed, but not so easy to verify:
210 * - EN_UPDATE/EN_CHANGE are handled very incorrectly (should be OK now)
211 * - undo for ME_JoinParagraphs doesn't store paragraph format ? (it does)
212 * - check/fix artificial EOL logic (bCursorAtEnd, hardly logical)
213 * - caret shouldn't be displayed when selection isn't empty
214 * - check refcounting in style management functions (looks perfect now, but no bugs is suspicious)
215 * - undo for setting default format (done, might be buggy)
216 * - styles might be not released properly (looks like they work like charm, but who knows?
224 #define NO_SHLWAPI_STREAM
229 WINE_DEFAULT_DEBUG_CHANNEL(richedit
);
232 HANDLE me_heap
= NULL
;
234 ME_TextBuffer
*ME_MakeText(void) {
236 ME_TextBuffer
*buf
= ALLOC_OBJ(ME_TextBuffer
);
238 ME_DisplayItem
*p1
= ME_MakeDI(diTextStart
);
239 ME_DisplayItem
*p2
= ME_MakeDI(diTextEnd
);
245 p1
->member
.para
.next_para
= p2
;
246 p2
->member
.para
.prev_para
= p1
;
247 p2
->member
.para
.nCharOfs
= 0;
251 buf
->pCharStyle
= NULL
;
257 static LRESULT
ME_StreamInText(ME_TextEditor
*editor
, DWORD dwFormat
, ME_InStream
*stream
, ME_Style
*style
)
259 WCHAR wszText
[STREAMIN_BUFFER_SIZE
+1];
262 TRACE("%08lx %p\n", dwFormat
, stream
);
269 ME_StreamInFill(stream
);
270 if (stream
->editstream
->dwError
)
276 if (!(dwFormat
& SF_UNICODE
))
278 /* FIXME? this is doomed to fail on true MBCS like UTF-8, luckily they're unlikely to be used as CP_ACP */
279 nWideChars
= MultiByteToWideChar(CP_ACP
, 0, stream
->buffer
, stream
->dwSize
, wszText
, STREAMIN_BUFFER_SIZE
);
284 nWideChars
= stream
->dwSize
>> 1;
285 pText
= (WCHAR
*)stream
->buffer
;
288 ME_InsertTextFromCursor(editor
, 0, pText
, nWideChars
, style
);
289 if (stream
->dwSize
< STREAMIN_BUFFER_SIZE
)
293 ME_CommitUndo(editor
);
298 void ME_RTFCharAttrHook(RTF_Info
*info
)
301 fmt
.cbSize
= sizeof(fmt
);
304 switch(info
->rtfMinor
)
307 /* FIXME add more flags once they're implemented */
308 fmt
.dwMask
= CFM_BOLD
| CFM_ITALIC
| CFM_UNDERLINE
| CFM_STRIKEOUT
| CFM_COLOR
| CFM_BACKCOLOR
| CFM_SIZE
| CFM_WEIGHT
;
309 fmt
.dwEffects
= CFE_AUTOCOLOR
| CFE_AUTOBACKCOLOR
;
310 fmt
.yHeight
= 12*20; /* 12pt */
314 fmt
.dwMask
= CFM_BOLD
;
315 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
318 fmt
.dwMask
= CFM_ITALIC
;
319 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
322 fmt
.dwMask
= CFM_UNDERLINE
;
323 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
324 fmt
.bUnderlineType
= CFU_CF1UNDERLINE
;
327 fmt
.dwMask
= CFM_UNDERLINE
;
331 fmt
.dwMask
= CFM_STRIKEOUT
;
332 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
336 case rtfSubScrShrink
:
337 case rtfSuperScrShrink
:
339 fmt
.dwMask
= CFM_SUBSCRIPT
|CFM_SUPERSCRIPT
;
340 if (info
->rtfMinor
== rtfSubScrShrink
) fmt
.dwEffects
= CFE_SUBSCRIPT
;
341 if (info
->rtfMinor
== rtfSuperScrShrink
) fmt
.dwEffects
= CFE_SUPERSCRIPT
;
342 if (info
->rtfMinor
== rtfNoSuperSub
) fmt
.dwEffects
= 0;
345 fmt
.dwMask
= CFM_BACKCOLOR
;
347 if (info
->rtfParam
== 0)
348 fmt
.dwEffects
= CFE_AUTOBACKCOLOR
;
349 else if (info
->rtfParam
!= rtfNoParam
)
351 RTFColor
*c
= RTFGetColor(info
, info
->rtfParam
);
352 fmt
.crTextColor
= (c
->rtfCBlue
<<16)|(c
->rtfCGreen
<<8)|(c
->rtfCRed
);
356 fmt
.dwMask
= CFM_COLOR
;
358 if (info
->rtfParam
== 0)
359 fmt
.dwEffects
= CFE_AUTOCOLOR
;
360 else if (info
->rtfParam
!= rtfNoParam
)
362 RTFColor
*c
= RTFGetColor(info
, info
->rtfParam
);
363 fmt
.crTextColor
= (c
->rtfCBlue
<<16)|(c
->rtfCGreen
<<8)|(c
->rtfCRed
);
367 if (info
->rtfParam
!= rtfNoParam
)
369 RTFFont
*f
= RTFGetFont(info
, info
->rtfParam
);
372 MultiByteToWideChar(CP_ACP
, 0, f
->rtfFName
, -1, fmt
.szFaceName
, sizeof(fmt
.szFaceName
)/sizeof(WCHAR
));
373 fmt
.szFaceName
[sizeof(fmt
.szFaceName
)/sizeof(WCHAR
)-1] = '\0';
374 fmt
.bCharSet
= f
->rtfFCharSet
;
375 fmt
.dwMask
= CFM_FACE
| CFM_CHARSET
;
380 fmt
.dwMask
= CFM_SIZE
;
381 if (info
->rtfParam
!= rtfNoParam
)
382 fmt
.yHeight
= info
->rtfParam
*10;
387 RTFFlushOutputBuffer(info
);
388 /* FIXME too slow ? how come ? */
389 style2
= ME_ApplyStyle(info
->style
, &fmt
);
390 ME_ReleaseStyle(info
->style
);
391 info
->style
= style2
;
395 /* FIXME this function doesn't get any information about context of the RTF tag, which is very bad,
396 the same tags mean different things in different contexts */
397 void ME_RTFParAttrHook(RTF_Info
*info
)
400 fmt
.cbSize
= sizeof(fmt
);
403 switch(info
->rtfMinor
)
405 case rtfParDef
: /* I'm not 100% sure what does it do, but I guess it restores default paragraph attributes */
406 fmt
.dwMask
= PFM_ALIGNMENT
| PFM_TABSTOPS
| PFM_OFFSET
| PFM_STARTINDENT
;
407 fmt
.wAlignment
= PFA_LEFT
;
409 fmt
.dxOffset
= fmt
.dxStartIndent
= 0;
412 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
413 fmt
.dwMask
= PFM_STARTINDENT
;
414 fmt
.dxStartIndent
= info
->rtfParam
+ fmt
.dxOffset
;
419 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
420 first
= fmt
.dxStartIndent
;
421 left
= info
->rtfParam
;
422 fmt
.dwMask
= PFM_STARTINDENT
|PFM_OFFSET
;
423 fmt
.dxStartIndent
= first
+ left
;
424 fmt
.dxOffset
= -first
;
428 fmt
.dwMask
= PFM_RIGHTINDENT
;
429 fmt
.dxRightIndent
= info
->rtfParam
;
433 fmt
.dwMask
= PFM_ALIGNMENT
;
434 fmt
.wAlignment
= PFA_LEFT
;
437 fmt
.dwMask
= PFM_ALIGNMENT
;
438 fmt
.wAlignment
= PFA_RIGHT
;
441 fmt
.dwMask
= PFM_ALIGNMENT
;
442 fmt
.wAlignment
= PFA_CENTER
;
445 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
446 if (!(fmt
.dwMask
& PFM_TABSTOPS
))
448 fmt
.dwMask
|= PFM_TABSTOPS
;
451 if (fmt
.cTabCount
< MAX_TAB_STOPS
)
452 fmt
.rgxTabs
[fmt
.cTabCount
++] = info
->rtfParam
;
456 RTFFlushOutputBuffer(info
);
457 /* FIXME too slow ? how come ?*/
458 ME_SetSelectionParaFormat(info
->editor
, &fmt
);
462 void ME_RTFReadHook(RTF_Info
*info
) {
463 switch(info
->rtfClass
)
466 switch(info
->rtfMajor
)
469 if (info
->stackTop
< maxStack
) {
470 memcpy(&info
->stack
[info
->stackTop
].fmt
, &info
->style
->fmt
, sizeof(CHARFORMAT2W
));
471 info
->stack
[info
->stackTop
].codePage
= info
->codePage
;
472 info
->stack
[info
->stackTop
].unicodeLength
= info
->unicodeLength
;
479 RTFFlushOutputBuffer(info
);
481 /* FIXME too slow ? how come ? */
482 s
= ME_ApplyStyle(info
->style
, &info
->stack
[info
->stackTop
].fmt
);
483 ME_ReleaseStyle(info
->style
);
485 info
->codePage
= info
->stack
[info
->stackTop
].codePage
;
486 info
->unicodeLength
= info
->stack
[info
->stackTop
].unicodeLength
;
492 switch(info
->rtfMajor
)
495 ME_RTFCharAttrHook(info
);
498 ME_RTFParAttrHook(info
);
506 ME_StreamInFill(ME_InStream
*stream
)
508 stream
->editstream
->dwError
= stream
->editstream
->pfnCallback(stream
->editstream
->dwCookie
,
510 sizeof(stream
->buffer
),
515 static LRESULT
ME_StreamIn(ME_TextEditor
*editor
, DWORD format
, EDITSTREAM
*stream
)
519 int from
, to
, to2
, nUndoMode
;
521 int nEventMask
= editor
->nEventMask
;
522 ME_InStream inStream
;
524 TRACE("stream==%p hWnd==%p format==0x%X\n", stream
, editor
->hWnd
, (UINT
)format
);
525 editor
->nEventMask
= 0;
527 ME_GetSelection(editor
, &from
, &to
);
528 if (format
& SFF_SELECTION
) {
529 style
= ME_GetSelectionInsertStyle(editor
);
531 ME_InternalDeleteText(editor
, from
, to
-from
);
534 style
= editor
->pBuffer
->pDefaultStyle
;
535 ME_AddRefStyle(style
);
536 SendMessageA(editor
->hWnd
, EM_SETSEL
, 0, 0);
537 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
));
539 ME_ClearTempStyle(editor
);
540 /* FIXME restore default paragraph formatting ! */
543 nUndoMode
= editor
->nUndoMode
;
544 editor
->nUndoMode
= umIgnore
;
546 inStream
.editstream
= stream
;
547 inStream
.editstream
->dwError
= 0;
553 /* Check if it's really RTF, and if it is not, use plain text */
554 ME_StreamInFill(&inStream
);
555 if (!inStream
.editstream
->dwError
)
557 if (strncmp(inStream
.buffer
, "{\\rtf1", 6) && strncmp(inStream
.buffer
, "{\\urtf", 6))
565 if (!inStream
.editstream
->dwError
)
567 if (format
& SF_RTF
) {
568 /* setup the RTF parser */
569 memset(&parser
, 0, sizeof parser
);
570 RTFSetEditStream(&parser
, &inStream
);
571 parser
.rtfFormat
= format
&(SF_TEXT
|SF_RTF
);
572 parser
.hwndEdit
= editor
->hWnd
;
573 parser
.editor
= editor
;
574 parser
.style
= style
;
577 RTFSetReadHook(&parser
, ME_RTFReadHook
);
582 RTFFlushOutputBuffer(&parser
);
585 style
= parser
.style
;
587 else if (format
& SF_TEXT
)
588 ME_StreamInText(editor
, format
, &inStream
, style
);
590 ERR("EM_STREAMIN without SF_TEXT or SF_RTF\n");
591 ME_GetSelection(editor
, &to
, &to2
);
592 /* put the cursor at the top */
593 if (!(format
& SFF_SELECTION
))
594 SendMessageA(editor
->hWnd
, EM_SETSEL
, 0, 0);
597 /* FIXME where to put cursor now ? */
601 editor
->nUndoMode
= nUndoMode
;
602 pUI
= ME_AddUndoItem(editor
, diUndoDeleteRun
, NULL
);
603 TRACE("from %d to %d\n", from
, to
);
604 if (pUI
&& from
< to
)
609 ME_CommitUndo(editor
);
610 ME_ReleaseStyle(style
);
611 editor
->nEventMask
= nEventMask
;
612 InvalidateRect(editor
->hWnd
, NULL
, TRUE
);
613 ME_UpdateRepaint(editor
);
614 if (!(format
& SFF_SELECTION
)) {
615 ME_ClearTempStyle(editor
);
617 ME_MoveCaret(editor
);
618 ME_SendSelChange(editor
);
625 ME_FindItemAtOffset(ME_TextEditor
*editor
, ME_DIType nItemType
, int nOffset
, int *nItemOffset
)
627 ME_DisplayItem
*item
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
629 while (item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= nOffset
)
630 item
= ME_FindItemFwd(item
, diParagraph
);
635 nOffset
-= item
->member
.para
.nCharOfs
;
636 if (nItemType
== diParagraph
) {
638 *nItemOffset
= nOffset
;
643 item
= ME_FindItemFwd(item
, diRun
);
644 } while (item
&& (item
->member
.run
.nCharOfs
+ ME_StrLen(item
->member
.run
.strText
) <= nOffset
));
646 nOffset
-= item
->member
.run
.nCharOfs
;
648 *nItemOffset
= nOffset
;
654 ME_TextEditor
*ME_MakeEditor(HWND hWnd
) {
655 ME_TextEditor
*ed
= ALLOC_OBJ(ME_TextEditor
);
659 ed
->pBuffer
= ME_MakeText();
661 ME_MakeFirstParagraph(hDC
, ed
->pBuffer
);
662 ReleaseDC(hWnd
, hDC
);
663 ed
->bCaretShown
= FALSE
;
665 ed
->pCursors
= ALLOC_N_OBJ(ME_Cursor
, ed
->nCursors
);
666 ed
->pCursors
[0].pRun
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diRun
);
667 ed
->pCursors
[0].nOffset
= 0;
668 ed
->pCursors
[1].pRun
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diRun
);
669 ed
->pCursors
[1].nOffset
= 0;
670 ed
->nLastTotalLength
= ed
->nTotalLength
= 0;
673 ed
->rgbBackColor
= -1;
674 ed
->bCaretAtEnd
= FALSE
;
677 ed
->pUndoStack
= ed
->pRedoStack
= NULL
;
678 ed
->nUndoMode
= umAddToUndo
;
680 ed
->nLastSelStart
= ed
->nLastSelEnd
= 0;
682 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
684 ed
->pFontCache
[i
].nRefs
= 0;
685 ed
->pFontCache
[i
].nAge
= 0;
686 ed
->pFontCache
[i
].hFont
= NULL
;
688 ME_CheckCharOffsets(ed
);
692 typedef struct tagME_GlobalDestStruct
696 } ME_GlobalDestStruct
;
698 static DWORD CALLBACK
ME_AppendToHGLOBAL(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
700 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
704 nMaxSize
= GlobalSize(pData
->hData
);
705 if (pData
->nLength
+cb
+1 >= cb
)
707 /* round up to 2^17 */
708 int nNewSize
= (((nMaxSize
+cb
+1)|0x1FFFF)+1) & 0xFFFE0000;
709 pData
->hData
= GlobalReAlloc(pData
->hData
, nNewSize
, 0);
711 pDest
= (BYTE
*)GlobalLock(pData
->hData
);
712 memcpy(pDest
+ pData
->nLength
, lpBuff
, cb
);
713 pData
->nLength
+= cb
;
714 pDest
[pData
->nLength
] = '\0';
715 GlobalUnlock(pData
->hData
);
721 static DWORD CALLBACK
ME_ReadFromHGLOBALUnicode(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
723 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
728 pDest
= (WORD
*)lpBuff
;
729 pSrc
= (WORD
*)GlobalLock(pData
->hData
);
730 for (i
= 0; i
<cb
&& pSrc
[pData
->nLength
+i
]; i
++) {
731 pDest
[i
] = pSrc
[pData
->nLength
+i
];
735 GlobalUnlock(pData
->hData
);
739 static DWORD CALLBACK
ME_ReadFromHGLOBALRTF(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
741 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
746 pSrc
= (BYTE
*)GlobalLock(pData
->hData
);
747 for (i
= 0; i
<cb
&& pSrc
[pData
->nLength
+i
]; i
++) {
748 pDest
[i
] = pSrc
[pData
->nLength
+i
];
752 GlobalUnlock(pData
->hData
);
756 void ME_DestroyEditor(ME_TextEditor
*editor
)
758 ME_DisplayItem
*pFirst
= editor
->pBuffer
->pFirst
;
759 ME_DisplayItem
*p
= pFirst
, *pNext
= NULL
;
762 ME_ClearTempStyle(editor
);
763 ME_EmptyUndoStack(editor
);
766 ME_DestroyDisplayItem(p
);
769 ME_ReleaseStyle(editor
->pBuffer
->pDefaultStyle
);
770 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
772 if (editor
->pFontCache
[i
].hFont
)
773 DeleteObject(editor
->pFontCache
[i
].hFont
);
779 static WCHAR wszClassName
[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '2', '0', 'W', 0};
780 static WCHAR wszClassName50
[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '5', '0', 'W', 0};
782 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
787 case DLL_PROCESS_ATTACH
:
788 DisableThreadLibraryCalls(hinstDLL
);
789 me_heap
= HeapCreate (0, 0x10000, 0);
790 ME_RegisterEditorClass(hinstDLL
);
793 case DLL_PROCESS_DETACH
:
794 UnregisterClassW(wszClassName
, 0);
795 UnregisterClassW(wszClassName50
, 0);
796 UnregisterClassA("RichEdit20A", 0);
797 UnregisterClassA("RichEdit50A", 0);
798 HeapDestroy (me_heap
);
806 #define UNSUPPORTED_MSG(e) \
808 FIXME(#e ": stub\n"); \
809 return DefWindowProcW(hWnd, msg, wParam, lParam);
811 /******************************************************************
812 * RichEditANSIWndProc (RICHED20.10)
814 LRESULT WINAPI
RichEditANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
) {
818 ME_TextEditor
*editor
= (ME_TextEditor
*)GetWindowLongW(hWnd
, 0);
819 TRACE("msg %d %08x %08lx\n", msg
, wParam
, lParam
);
822 UNSUPPORTED_MSG(EM_AUTOURLDETECT
)
823 UNSUPPORTED_MSG(EM_CHARFROMPOS
)
824 UNSUPPORTED_MSG(EM_DISPLAYBAND
)
825 UNSUPPORTED_MSG(EM_EXLIMITTEXT
)
826 UNSUPPORTED_MSG(EM_EXLINEFROMCHAR
)
827 UNSUPPORTED_MSG(EM_FINDTEXT
)
828 UNSUPPORTED_MSG(EM_FINDTEXTEX
)
829 UNSUPPORTED_MSG(EM_FINDWORDBREAK
)
830 UNSUPPORTED_MSG(EM_FMTLINES
)
831 UNSUPPORTED_MSG(EM_FORMATRANGE
)
832 UNSUPPORTED_MSG(EM_GETAUTOURLDETECT
)
833 UNSUPPORTED_MSG(EM_GETBIDIOPTIONS
)
834 UNSUPPORTED_MSG(EM_GETEDITSTYLE
)
835 UNSUPPORTED_MSG(EM_GETFIRSTVISIBLELINE
)
836 UNSUPPORTED_MSG(EM_GETIMECOMPMODE
)
837 /* UNSUPPORTED_MSG(EM_GETIMESTATUS) missing in Wine headers */
838 UNSUPPORTED_MSG(EM_GETLANGOPTIONS
)
839 UNSUPPORTED_MSG(EM_GETLIMITTEXT
)
840 UNSUPPORTED_MSG(EM_GETLINE
)
841 UNSUPPORTED_MSG(EM_GETLINECOUNT
)
842 /* UNSUPPORTED_MSG(EM_GETOLEINTERFACE) separate stub */
843 UNSUPPORTED_MSG(EM_GETOPTIONS
)
844 UNSUPPORTED_MSG(EM_GETPASSWORDCHAR
)
845 UNSUPPORTED_MSG(EM_GETRECT
)
846 UNSUPPORTED_MSG(EM_GETREDONAME
)
847 UNSUPPORTED_MSG(EM_GETSCROLLPOS
)
848 UNSUPPORTED_MSG(EM_GETTEXTMODE
)
849 UNSUPPORTED_MSG(EM_GETTYPOGRAPHYOPTIONS
)
850 UNSUPPORTED_MSG(EM_GETUNDONAME
)
851 UNSUPPORTED_MSG(EM_GETWORDBREAKPROC
)
852 UNSUPPORTED_MSG(EM_GETWORDBREAKPROCEX
)
853 UNSUPPORTED_MSG(EM_GETZOOM
)
854 UNSUPPORTED_MSG(EM_HIDESELECTION
)
855 UNSUPPORTED_MSG(EM_LIMITTEXT
) /* also known as EM_SETLIMITTEXT */
856 UNSUPPORTED_MSG(EM_LINEFROMCHAR
)
857 UNSUPPORTED_MSG(EM_LINEINDEX
)
858 UNSUPPORTED_MSG(EM_LINELENGTH
)
859 UNSUPPORTED_MSG(EM_PASTESPECIAL
)
860 /* UNSUPPORTED_MSG(EM_POSFROMCHARS) missing in Wine headers */
861 UNSUPPORTED_MSG(EM_REQUESTRESIZE
)
862 UNSUPPORTED_MSG(EM_SCROLL
)
863 UNSUPPORTED_MSG(EM_SCROLLCARET
)
864 UNSUPPORTED_MSG(EM_SELECTIONTYPE
)
865 UNSUPPORTED_MSG(EM_SETBIDIOPTIONS
)
866 UNSUPPORTED_MSG(EM_SETEDITSTYLE
)
867 UNSUPPORTED_MSG(EM_SETFONTSIZE
)
868 UNSUPPORTED_MSG(EM_SETLANGOPTIONS
)
869 UNSUPPORTED_MSG(EM_SETOLECALLBACK
)
870 UNSUPPORTED_MSG(EM_SETOPTIONS
)
871 UNSUPPORTED_MSG(EM_SETPALETTE
)
872 UNSUPPORTED_MSG(EM_SETPASSWORDCHAR
)
873 UNSUPPORTED_MSG(EM_SETRECT
)
874 UNSUPPORTED_MSG(EM_SETRECTNP
)
875 UNSUPPORTED_MSG(EM_SETSCROLLPOS
)
876 UNSUPPORTED_MSG(EM_SETTABSTOPS
)
877 UNSUPPORTED_MSG(EM_SETTARGETDEVICE
)
878 UNSUPPORTED_MSG(EM_SETTEXTEX
)
879 UNSUPPORTED_MSG(EM_SETTEXTMODE
)
880 UNSUPPORTED_MSG(EM_SETTYPOGRAPHYOPTIONS
)
881 UNSUPPORTED_MSG(EM_SETUNDOLIMIT
)
882 UNSUPPORTED_MSG(EM_SETWORDBREAKPROC
)
883 UNSUPPORTED_MSG(EM_SETWORDBREAKPROCEX
)
884 UNSUPPORTED_MSG(EM_SHOWSCROLLBAR
)
885 UNSUPPORTED_MSG(EM_SETZOOM
)
886 UNSUPPORTED_MSG(WM_SETFONT
)
887 UNSUPPORTED_MSG(WM_STYLECHANGING
)
888 UNSUPPORTED_MSG(WM_STYLECHANGED
)
889 /* UNSUPPORTED_MSG(WM_UNICHAR) FIXME missing in Wine headers */
891 /* Messages specific to Richedit controls */
894 return ME_StreamIn(editor
, wParam
, (EDITSTREAM
*)lParam
);
896 return ME_StreamOut(editor
, wParam
, (EDITSTREAM
*)lParam
);
899 UINT code
= DLGC_WANTCHARS
|DLGC_WANTARROWS
;
900 if (GetWindowLongW(hWnd
, GWL_STYLE
)&ES_WANTRETURN
)
901 code
|= 0; /* FIXME what can we do here ? ask for messages and censor them ? */
906 CREATESTRUCTW
*pcs
= (CREATESTRUCTW
*)lParam
;
907 editor
= ME_MakeEditor(hWnd
);
908 SetWindowLongW(hWnd
, 0, (long)editor
);
909 pcs
= 0; /* ignore */
912 case EM_EMPTYUNDOBUFFER
:
913 ME_EmptyUndoStack(editor
);
917 /* Note: wParam/lParam can be NULL */
919 PUINT pfrom
= wParam
? (PUINT
)wParam
: &from
;
920 PUINT pto
= lParam
? (PUINT
)lParam
: &to
;
921 ME_GetSelection(editor
, pfrom
, pto
);
922 if ((*pfrom
|*pto
) & 0xFFFF0000)
924 return MAKELONG(*pfrom
,*pto
);
928 CHARRANGE
*pRange
= (CHARRANGE
*)lParam
;
929 ME_GetSelection(editor
, (int *)&pRange
->cpMin
, (int *)&pRange
->cpMax
);
933 return editor
->pUndoStack
!= NULL
;
935 return editor
->pRedoStack
!= NULL
;
944 ME_SetSelection(editor
, wParam
, lParam
);
946 ME_SendSelChange(editor
);
951 CHARRANGE
*pRange
= (CHARRANGE
*)lParam
;
952 ME_SetSelection(editor
, pRange
->cpMin
, pRange
->cpMax
);
955 ME_SendSelChange(editor
);
958 case EM_SETBKGNDCOLOR
:
960 LRESULT lColor
= ME_GetBackColor(editor
);
962 editor
->rgbBackColor
= -1;
964 editor
->rgbBackColor
= lParam
;
965 InvalidateRect(hWnd
, NULL
, TRUE
);
970 return editor
->nModifyStep
== 0 ? 0 : 1;
974 editor
->nModifyStep
= 0x80000000;
976 editor
->nModifyStep
= 0;
982 long nStyle
= GetWindowLongW(hWnd
, GWL_STYLE
);
984 nStyle
|= ES_READONLY
;
986 nStyle
&= ~ES_READONLY
;
987 SetWindowLongW(hWnd
, GWL_STYLE
, nStyle
);
991 case EM_SETEVENTMASK
:
992 editor
->nEventMask
= lParam
;
994 case EM_GETEVENTMASK
:
995 return editor
->nEventMask
;
996 case EM_SETCHARFORMAT
:
998 CHARFORMAT2W buf
, *p
;
999 BOOL bRepaint
= TRUE
;
1000 p
= ME_ToCF2W(&buf
, (CHARFORMAT2W
*)lParam
);
1002 ME_SetDefaultCharFormat(editor
, p
);
1003 else if (wParam
== (SCF_WORD
| SCF_SELECTION
))
1004 FIXME("word selection not supported\n");
1005 else if (wParam
== SCF_ALL
)
1006 ME_SetCharFormat(editor
, 0, ME_GetTextLength(editor
), p
);
1009 ME_GetSelection(editor
, &from
, &to
);
1010 bRepaint
= (from
!= to
);
1011 ME_SetSelectionCharFormat(editor
, p
);
1013 ME_CommitUndo(editor
);
1015 ME_UpdateRepaint(editor
);
1018 case EM_GETCHARFORMAT
:
1021 tmp
.cbSize
= sizeof(tmp
);
1023 ME_GetDefaultCharFormat(editor
, &tmp
);
1025 ME_GetSelectionCharFormat(editor
, &tmp
);
1026 ME_CopyToCFAny((CHARFORMAT2W
*)lParam
, &tmp
);
1029 case EM_SETPARAFORMAT
:
1030 ME_SetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
1031 ME_UpdateRepaint(editor
);
1032 ME_CommitUndo(editor
);
1034 case EM_GETPARAFORMAT
:
1035 ME_GetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
1039 int nPos
= editor
->nScrollPosY
, nEnd
= editor
->nTotalLength
- editor
->sizeWindow
.cy
;
1040 nPos
+= 8 * lParam
; /* FIXME follow the original */
1045 if (nPos
!= editor
->nScrollPosY
) {
1046 ScrollWindow(hWnd
, 0, editor
->nScrollPosY
-nPos
, NULL
, NULL
);
1047 editor
->nScrollPosY
= nPos
;
1048 SetScrollPos(hWnd
, SB_VERT
, nPos
, TRUE
);
1051 return TRUE
; /* Should return false if a single line richedit control */
1056 ME_GetSelection(editor
, &from
, &to
);
1057 ME_InternalDeleteText(editor
, from
, to
-from
);
1058 ME_CommitUndo(editor
);
1059 ME_UpdateRepaint(editor
);
1066 LPWSTR wszText
= ME_ToUnicode(hWnd
, (void *)lParam
);
1067 size_t len
= lstrlenW(wszText
);
1068 TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText
));
1070 ME_GetSelection(editor
, &from
, &to
);
1071 style
= ME_GetSelectionInsertStyle(editor
);
1072 ME_InternalDeleteText(editor
, from
, to
-from
);
1073 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, style
);
1074 ME_ReleaseStyle(style
);
1075 ME_EndToUnicode(hWnd
, wszText
);
1076 /* drop temporary style if line end */
1077 /* FIXME question: does abc\n mean: put abc, clear temp style, put \n? (would require a change) */
1078 if (len
>0 && wszText
[len
-1] == '\n')
1079 ME_ClearTempStyle(editor
);
1081 ME_CommitUndo(editor
);
1083 ME_EmptyUndoStack(editor
);
1084 ME_UpdateRepaint(editor
);
1089 LPWSTR wszText
= ME_ToUnicode(hWnd
, (void *)lParam
);
1090 TRACE("WM_SETTEXT - %s\n", (char *)(wszText
)); /* debugstr_w() */
1091 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
));
1092 /* uses default style! */
1093 ME_InsertTextFromCursor(editor
, 0, wszText
, -1, editor
->pBuffer
->pDefaultStyle
);
1094 ME_EndToUnicode(hWnd
, wszText
);
1095 ME_CommitUndo(editor
);
1096 ME_EmptyUndoStack(editor
);
1097 ME_UpdateRepaint(editor
);
1102 UINT nRTFFormat
= RegisterClipboardFormatA("Rich Text Format");
1103 if (IsClipboardFormatAvailable(nRTFFormat
))
1105 if (IsClipboardFormatAvailable(CF_UNICODETEXT
))
1113 ME_GlobalDestStruct gds
;
1114 UINT nRTFFormat
= RegisterClipboardFormatA("Rich Text Format");
1117 if (IsClipboardFormatAvailable(nRTFFormat
))
1118 cf
= nRTFFormat
, dwFormat
= SF_RTF
;
1119 else if (IsClipboardFormatAvailable(CF_UNICODETEXT
))
1120 cf
= CF_UNICODETEXT
, dwFormat
= SF_TEXT
|SF_UNICODE
;
1124 if (!OpenClipboard(hWnd
))
1126 gds
.hData
= GetClipboardData(cf
);
1128 es
.dwCookie
= (DWORD
)&gds
;
1129 es
.pfnCallback
= dwFormat
== SF_RTF
? ME_ReadFromHGLOBALRTF
: ME_ReadFromHGLOBALUnicode
;
1130 SendMessageW(hWnd
, EM_STREAMIN
, dwFormat
|SFF_SELECTION
, (LPARAM
)&es
);
1142 ME_GlobalDestStruct gds
;
1144 if (!OpenClipboard(hWnd
))
1148 ME_GetSelection(editor
, &from
, &to
);
1149 pars
= ME_CountParagraphsBetween(editor
, from
, to
);
1150 hData
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(WCHAR
)*(to
-from
+pars
+1));
1151 data
= (WCHAR
*)GlobalLock(hData
);
1152 ME_GetTextW(editor
, data
, from
, to
-from
, TRUE
);
1153 GlobalUnlock(hData
);
1155 gds
.hData
= GlobalAlloc(GMEM_MOVEABLE
, 0);
1157 es
.dwCookie
= (DWORD
)&gds
;
1158 es
.pfnCallback
= ME_AppendToHGLOBAL
;
1159 SendMessageW(hWnd
, EM_STREAMOUT
, SFF_SELECTION
|SF_RTF
, (LPARAM
)&es
);
1160 GlobalReAlloc(gds
.hData
, gds
.nLength
+1, 0);
1162 SetClipboardData(CF_UNICODETEXT
, hData
);
1163 SetClipboardData(RegisterClipboardFormatA("Rich Text Format"), gds
.hData
);
1168 ME_InternalDeleteText(editor
, from
, to
-from
);
1169 ME_CommitUndo(editor
);
1170 ME_UpdateRepaint(editor
);
1174 case WM_GETTEXTLENGTH
:
1175 return ME_GetTextLength(editor
);
1176 case EM_GETTEXTLENGTHEX
:
1177 return ME_GetTextLengthEx(editor
, (GETTEXTLENGTHEX
*)wParam
);
1180 TEXTRANGEW tr
; /* W and A differ only by rng->lpstrText */
1182 tr
.chrg
.cpMax
= wParam
-1;
1183 tr
.lpstrText
= (WCHAR
*)lParam
;
1184 return RichEditANSIWndProc(hWnd
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
);
1188 GETTEXTEX
*ex
= (GETTEXTEX
*)wParam
;
1191 FIXME("Unhandled EM_GETTEXTEX flags 0x%lx\n",ex
->flags
);
1193 if (IsWindowUnicode(hWnd
))
1194 return ME_GetTextW(editor
, (LPWSTR
)lParam
, 0, ex
->cb
, FALSE
);
1197 LPWSTR buffer
= HeapAlloc(GetProcessHeap(),0,ex
->cb
*sizeof(WCHAR
));
1198 DWORD buflen
= ex
->cb
;
1202 buflen
= ME_GetTextW(editor
, buffer
, 0, buflen
, FALSE
);
1203 rc
= WideCharToMultiByte(ex
->codepage
, flags
, buffer
, buflen
, (LPSTR
)lParam
, ex
->cb
, ex
->lpDefaultChar
, ex
->lpUsedDefaultChar
);
1205 HeapFree(GetProcessHeap(),0,buffer
);
1212 TEXTRANGEW tr
; /* W and A differ only by rng->lpstrText */
1213 ME_GetSelection(editor
, &from
, &to
);
1214 tr
.chrg
.cpMin
= from
;
1216 tr
.lpstrText
= (WCHAR
*)lParam
;
1217 return RichEditANSIWndProc(hWnd
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
);
1219 case EM_GETTEXTRANGE
:
1221 TEXTRANGEW
*rng
= (TEXTRANGEW
*)lParam
;
1222 if (IsWindowUnicode(hWnd
))
1223 return ME_GetTextW(editor
, rng
->lpstrText
, rng
->chrg
.cpMin
, rng
->chrg
.cpMax
-rng
->chrg
.cpMin
, FALSE
);
1226 int nLen
= rng
->chrg
.cpMax
-rng
->chrg
.cpMin
;
1227 WCHAR
*p
= ALLOC_N_OBJ(WCHAR
, nLen
+1);
1228 int nChars
= ME_GetTextW(editor
, p
, rng
->chrg
.cpMin
, nLen
, FALSE
);
1229 /* FIXME this is a potential security hole (buffer overrun)
1230 if you know more about wchar->mbyte conversion please explain
1232 WideCharToMultiByte(CP_ACP
, 0, p
, nChars
+1, (char *)rng
->lpstrText
, nLen
+1, NULL
, NULL
);
1236 return ME_GetTextW(editor
, rng
->lpstrText
, rng
->chrg
.cpMin
, rng
->chrg
.cpMax
-rng
->chrg
.cpMin
, FALSE
);
1239 ME_CommitUndo(editor
);
1240 ME_WrapMarkedParagraphs(editor
);
1241 ME_MoveCaret(editor
);
1244 ME_DestroyEditor(editor
);
1245 SetWindowLongW(hWnd
, 0, 0);
1247 case WM_LBUTTONDOWN
:
1249 ME_LButtonDown(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
1253 if (GetCapture() == hWnd
)
1254 ME_MouseMove(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
1257 if (GetCapture() == hWnd
)
1261 hDC
= BeginPaint(hWnd
, &ps
);
1262 ME_PaintContent(editor
, hDC
, FALSE
, &ps
.rcPaint
);
1263 EndPaint(hWnd
, &ps
);
1266 ME_ShowCaret(editor
);
1267 ME_SendOldNotify(editor
, EN_SETFOCUS
);
1270 ME_HideCaret(editor
);
1271 ME_SendOldNotify(editor
, EN_KILLFOCUS
);
1275 HDC hDC
= (HDC
)wParam
;
1277 COLORREF rgbBG
= ME_GetBackColor(editor
);
1278 if (GetUpdateRect(hWnd
,&rc
,TRUE
))
1280 HBRUSH hbr
= CreateSolidBrush(rgbBG
);
1281 FillRect(hDC
, &rc
, hbr
);
1287 TRACE("editor wnd command = %d\n", LOWORD(wParam
));
1290 if (ME_ArrowKey(editor
, LOWORD(wParam
), GetKeyState(VK_CONTROL
)<0)) {
1291 ME_CommitUndo(editor
);
1292 ME_EnsureVisible(editor
, editor
->pCursors
[0].pRun
);
1294 ME_MoveCaret(editor
);
1298 if (GetKeyState(VK_CONTROL
)<0)
1300 if (LOWORD(wParam
)=='W')
1304 ME_GetSelectionCharFormat(editor
, &chf
);
1305 ME_DumpStyleToBuf(&chf
, buf
);
1306 MessageBoxA(NULL
, buf
, "Style dump", MB_OK
);
1308 if (LOWORD(wParam
)=='Q')
1310 ME_CheckCharOffsets(editor
);
1317 if (GetWindowLongW(editor
->hWnd
, GWL_STYLE
) & ES_READONLY
) {
1318 MessageBeep(MB_ICONERROR
);
1319 return 0; /* FIXME really 0 ? */
1321 wstr
= LOWORD(wParam
);
1322 if (((unsigned)wstr
)>=' ' || wstr
=='\r' || wstr
=='\t') {
1323 /* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */
1324 ME_Style
*style
= ME_GetInsertStyle(editor
, 0);
1325 ME_SaveTempStyle(editor
);
1326 ME_InsertTextFromCursor(editor
, 0, &wstr
, 1, style
);
1327 ME_ReleaseStyle(style
);
1328 ME_CommitUndo(editor
);
1329 ME_UpdateRepaint(editor
);
1335 int nPos
= editor
->nScrollPosY
;
1336 si
.cbSize
= sizeof(SCROLLINFO
);
1337 si
.fMask
= SIF_PAGE
|SIF_POS
|SIF_RANGE
|SIF_TRACKPOS
;
1338 GetScrollInfo(hWnd
, SB_VERT
, &si
);
1339 switch(LOWORD(wParam
)) {
1341 nPos
-= 24; /* FIXME follow the original */
1342 if (nPos
<0) nPos
= 0;
1346 int nEnd
= editor
->nTotalLength
- editor
->sizeWindow
.cy
;
1347 nPos
+= 24; /* FIXME follow the original */
1348 if (nPos
>=nEnd
) nPos
= nEnd
;
1352 nPos
-= editor
->sizeWindow
.cy
;
1353 if (nPos
<0) nPos
= 0;
1356 nPos
+= editor
->sizeWindow
.cy
;
1357 if (nPos
>=editor
->nTotalLength
) nPos
= editor
->nTotalLength
-1;
1360 case SB_THUMBPOSITION
:
1361 nPos
= si
.nTrackPos
;
1364 if (nPos
!= editor
->nScrollPosY
) {
1365 ScrollWindow(hWnd
, 0, editor
->nScrollPosY
-nPos
, NULL
, NULL
);
1366 editor
->nScrollPosY
= nPos
;
1367 SetScrollPos(hWnd
, SB_VERT
, nPos
, TRUE
);
1374 int gcWheelDelta
= 0, nPos
= editor
->nScrollPosY
, nEnd
= editor
->nTotalLength
- editor
->sizeWindow
.cy
;
1375 UINT pulScrollLines
;
1376 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
1377 gcWheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
1378 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
1379 nPos
+= pulScrollLines
* (gcWheelDelta
/ WHEEL_DELTA
) * 8; /* FIXME follow the original */
1384 if (nPos
!= editor
->nScrollPosY
) {
1385 ScrollWindow(hWnd
, 0, editor
->nScrollPosY
-nPos
, NULL
, NULL
);
1386 editor
->nScrollPosY
= nPos
;
1387 SetScrollPos(hWnd
, SB_VERT
, nPos
, TRUE
);
1394 ME_MarkAllForWrapping(editor
);
1395 ME_WrapMarkedParagraphs(editor
);
1396 ME_UpdateScrollBar(editor
);
1398 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
1400 case EM_GETOLEINTERFACE
:
1402 LPVOID
*ppvObj
= (LPVOID
*) lParam
;
1403 FIXME("EM_GETOLEINTERFACE %p: stub\n", ppvObj
);
1404 return CreateIRichEditOle(ppvObj
);
1408 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
1413 /******************************************************************
1414 * RichEdit10ANSIWndProc (RICHED20.9)
1416 LRESULT WINAPI
RichEdit10ANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1418 /* FIXME: this is NOT the same as 2.0 version */
1419 return RichEditANSIWndProc(hWnd
, msg
, wParam
, lParam
);
1422 void ME_SendOldNotify(ME_TextEditor
*editor
, int nCode
)
1424 HWND hWnd
= editor
->hWnd
;
1425 SendMessageA(GetParent(hWnd
), WM_COMMAND
, (nCode
<<16)|GetWindowLongW(hWnd
, GWLP_ID
), (LPARAM
)hWnd
);
1428 int ME_CountParagraphsBetween(ME_TextEditor
*editor
, int from
, int to
)
1430 ME_DisplayItem
*item
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
1433 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= from
)
1434 item
= item
->member
.para
.next_para
;
1437 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= to
) {
1438 item
= item
->member
.para
.next_para
;
1445 int ME_GetTextW(ME_TextEditor
*editor
, WCHAR
*buffer
, int nStart
, int nChars
, int bCRLF
)
1447 ME_DisplayItem
*item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
1458 int nLen
= ME_StrLen(item
->member
.run
.strText
) - nStart
;
1461 CopyMemory(buffer
, item
->member
.run
.strText
->szData
+ nStart
, sizeof(WCHAR
)*nLen
);
1468 item
= ME_FindItemFwd(item
, diRun
);
1471 while(nChars
&& item
)
1473 int nLen
= ME_StrLen(item
->member
.run
.strText
);
1477 if (item
->member
.run
.nFlags
& MERF_ENDPARA
)
1487 CopyMemory(buffer
, item
->member
.run
.strText
->szData
, sizeof(WCHAR
)*nLen
);
1497 item
= ME_FindItemFwd(item
, diRun
);
1503 void ME_RegisterEditorClass(HINSTANCE hInstance
)
1509 wcW
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
;
1510 wcW
.lpfnWndProc
= RichEditANSIWndProc
;
1513 wcW
.hInstance
= NULL
; /* hInstance would register DLL-local class */
1515 wcW
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
1516 wcW
.hbrBackground
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
1517 wcW
.lpszMenuName
= NULL
;
1518 wcW
.lpszClassName
= wszClassName
;
1519 bResult
= RegisterClassW(&wcW
);
1521 wcW
.lpszClassName
= wszClassName50
;
1522 bResult
= RegisterClassW(&wcW
);
1525 wcA
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
;
1526 wcA
.lpfnWndProc
= RichEditANSIWndProc
;
1529 wcA
.hInstance
= NULL
; /* hInstance would register DLL-local class */
1531 wcA
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
1532 wcA
.hbrBackground
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
1533 wcA
.lpszMenuName
= NULL
;
1534 wcA
.lpszClassName
= "RichEdit20A";
1535 bResult
= RegisterClassA(&wcA
);
1537 wcA
.lpszClassName
= "RichEdit50A";
1538 bResult
= RegisterClassA(&wcA
);
1541 /******************************************************************
1542 * CreateTextServices (RICHED20.4)
1544 * FIXME should be ITextHost instead of void*
1546 HRESULT WINAPI
CreateTextServices(IUnknown
*punkOuter
, void *pITextHost
,
1550 /* FIXME should support aggregation */
1552 return CLASS_E_NOAGGREGATION
;
1554 return E_FAIL
; /* E_NOTIMPL isn't allowed by MSDN */
1557 /******************************************************************
1558 * REExtendedRegisterClass (RICHED20.8)
1560 * FIXME undocumented
1562 void WINAPI
REExtendedRegisterClass(void)