- WM_COPY (and WM_CUT) can now put both Unicode and RTF format (thanks
[wine/wine-kai.git] / dlls / riched20 / editor.c
blob5980fad90669436a311fbabc3c4600fc3b4673ed
1 /*
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
21 /*
22 API implementation status:
24 Messages (ANSI versions not done yet)
25 - EM_AUTOURLDETECT 2.0
26 - EM_CANPASTE
27 + EM_CANREDO 2.0
28 + EM_CANUNDO
29 - EM_CHARFROMPOS
30 - EM_DISPLAYBAND
31 + EM_EMPTYUNDOBUFFER
32 + EM_EXGETSEL
33 - EM_EXLIMITTEXT
34 - EM_EXLINEFROMCHAR
35 + EM_EXSETSEL
36 - EM_FINDTEXT
37 - EM_FINDTEXTEX
38 - EM_FINDWORDBREAK
39 - EM_FMTLINES
40 - EM_FORMATRANGE
41 - EM_GETCHARFORMAT (partly done)
42 + EM_GETEVENTMASK
43 - EM_GETFIRSTVISIBLELINE
44 - EM_GETIMECOLOR 1.0asian
45 - EM_GETIMECOMPMODE 2.0
46 - EM_GETIMEOPTIONS 1.0asian
47 - EM_GETIMESTATUS
48 - EM_GETLANGOPTIONS 2.0
49 - EM_GETLIMITTEXT
50 - EM_GETLINE
51 - EM_GETLINECOUNT returns number of rows, not of paragraphs
52 + EM_GETMODIFY
53 - EM_GETOLEINTERFACE
54 - EM_GETOPTIONS
55 + EM_GETPARAFORMAT
56 - EM_GETPUNCTUATION 1.0asian
57 - EM_GETRECT
58 - EM_GETREDONAME 2.0
59 + EM_GETSEL
60 + EM_GETSELTEXT (ANSI&Unicode)
61 ! - EM_GETTHUMB
62 - EM_GETTEXTMODE 2.0
63 ? + EM_GETTEXTRANGE (ANSI&Unicode)
64 - EM_GETUNDONAME
65 - EM_GETWORDBREAKPROC
66 - EM_GETWORDBREAKPROCEX
67 - EM_GETWORDWRAPMODE 1.0asian
68 - EM_HIDESELECTION
69 - EM_LIMITTEXT
70 - EM_LINEFROMCHAR
71 - EM_LINEINDEX
72 - EM_LINELENGTH
73 - EM_LINESCROLL
74 - EM_PASTESPECIAL
75 - EM_POSFROMCHARS
76 - EM_REDO 2.0
77 - EM_REQUESTRESIZE
78 + EM_REPLACESEL (proper style?) ANSI&Unicode
79 - EM_SCROLL
80 - EM_SCROLLCARET
81 - EM_SELECTIONTYPE
82 + EM_SETBKGNDCOLOR
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
88 - EM_SETLIMITTEXT
89 + EM_SETMODIFY (not sure if implementation is correct)
90 - EM_SETOLECALLBACK
91 - EM_SETOPTIONS
92 + EM_SETPARAFORMAT
93 - EM_SETPUNCTUATION 1.0asian
94 + EM_SETREADONLY no beep on modification attempt
95 - EM_SETRECT
96 - EM_SETRECTNP (EM_SETRECT without repainting) - not supported in RICHEDIT
97 + EM_SETSEL
98 - EM_SETTARGETDEVICE
99 - EM_SETTEXTMODE 2.0
100 - EM_SETUNDOLIMIT 2.0
101 - EM_SETWORDBREAKPROC
102 - EM_SETWORDBREAKPROCEX
103 - EM_SETWORDWRAPMODE 1.0asian
104 - EM_STOPGROUPTYPING 2.0
105 - EM_STREAMIN
106 - EM_STREAMOUT
107 - EM_UNDO
108 + WM_CHAR
109 + WM_CLEAR
110 + WM_COPY
111 + WM_CUT
112 + WM_GETDLGCODE (the current implementation is incomplete)
113 + WM_GETTEXT (ANSI&Unicode)
114 + WM_GETTEXTLENGTH (ANSI version sucks)
115 + WM_PASTE
116 - WM_SETFONT
117 + WM_SETTEXT (resets undo stack !) (proper style?) ANSI&Unicode
118 - WM_STYLECHANGING
119 - WM_STYLECHANGED (things like read-only flag)
120 - WM_UNICHAR
122 Notifications
124 * EN_CHANGE (sent from the wrong place)
125 - EN_CORRECTTEXT
126 - EN_DROPFILES
127 - EN_ERRSPACE
128 - EN_HSCROLL
129 - EN_IMECHANGE
130 + EN_KILLFOCUS
131 - EN_LINK
132 - EN_MAXTEXT
133 - EN_MSGFILTER
134 - EN_OLEOPFAILED
135 - EN_PROTECTED
136 - EN_REQUESTRESIZE
137 - EN_SAVECLIPBOARD
138 + EN_SELCHANGE
139 + EN_SETFOCUS
140 - EN_STOPNOUNDO
141 * EN_UPDATE (sent from the wrong place)
142 - EN_VSCROLL
144 Styles
146 - ES_AUTOHSCROLL
147 - ES_AUTOVSCROLL
148 - ES_CENTER
149 - ES_DISABLENOSCROLL (scrollbar is always visible)
150 - ES_EX_NOCALLOLEINIT
151 - ES_LEFT
152 - ES_MULTILINE (currently single line controls aren't supported)
153 - ES_NOIME
154 - ES_READONLY (I'm not sure if beeping is the proper behaviour)
155 - ES_RIGHT
156 - ES_SAVESEL
157 - ES_SELFIME
158 - ES_SUNKEN
159 - ES_VERTICAL
160 - ES_WANTRETURN (don't know how to do WM_GETDLGCODE part)
161 - WS_SETFONT
162 - WS_HSCROLL
163 - WS_VSCROLL
167 * RICHED20 TODO (incomplete):
169 * - font caching
170 * - add remaining CHARFORMAT/PARAFORMAT fields
171 * - right/center align should strip spaces from the beginning
172 * - more advanced navigation (Ctrl-arrows, PageUp/PageDn)
173 * - tabs
174 * - pictures (not just smiling faces that lack API support ;-) )
175 * - OLE objects
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
182 * - find/replace
183 * - how to implement EM_FORMATRANGE and EM_DISPLAYBAND ? (Mission Impossible)
184 * - italic cursor with italic fonts
185 * - IME
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?
205 #include "editor.h"
206 #include <ole2.h>
207 #include <richole.h>
208 #include <winreg.h>
209 #define NO_SHLWAPI_STREAM
210 #include <shlwapi.h>
212 #include "rtf.h"
214 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
216 int me_debug = 0;
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);
226 p1->prev = NULL;
227 p1->next = p2;
228 p2->prev = p1;
229 p2->next = NULL;
230 p1->member.para.next_para = p2;
231 p2->member.para.prev_para = p1;
232 p2->member.para.nCharOfs = 0;
234 buf->pFirst = p1;
235 buf->pLast = p2;
236 buf->pCharStyle = NULL;
238 return buf;
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);
249 stream->dwError = 0;
251 do {
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);
257 if (stream->dwError)
258 break;
259 if (!nDataSize)
260 break;
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);
267 else
268 nWideChars = nDataSize>>1;
269 ME_InsertTextFromCursor(editor, 0, wszText, nWideChars, style);
270 if (nDataSize<STREAMIN_BUFFER_SIZE)
271 break;
272 } while(1);
273 ME_CommitUndo(editor);
274 ME_Repaint(editor);
275 return 0;
278 void ME_RTFCharAttrHook(RTF_Info *info)
280 CHARFORMAT2A fmt;
281 fmt.cbSize = sizeof(fmt);
282 fmt.dwMask = 0;
284 switch(info->rtfMinor)
286 case rtfPlain:
287 FIXME("rtfPlain: how plain should it be ?\n");
288 fmt.dwMask = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_COLOR | CFM_BACKCOLOR;
289 fmt.dwEffects = CFE_AUTOCOLOR | CFE_AUTOBACKCOLOR;
290 break;
291 case rtfBold:
292 fmt.dwMask = CFM_BOLD;
293 fmt.dwEffects = info->rtfParam ? fmt.dwMask : 0;
294 break;
295 case rtfItalic:
296 fmt.dwMask = CFM_ITALIC;
297 fmt.dwEffects = info->rtfParam ? fmt.dwMask : 0;
298 break;
299 case rtfUnderline:
300 fmt.dwMask = CFM_UNDERLINE;
301 fmt.dwEffects = info->rtfParam ? fmt.dwMask : 0;
302 break;
303 case rtfStrikeThru:
304 fmt.dwMask = CFM_STRIKEOUT;
305 fmt.dwEffects = info->rtfParam ? fmt.dwMask : 0;
306 break;
307 case rtfBackColor:
308 fmt.dwMask = CFM_BACKCOLOR;
309 fmt.dwEffects = 0;
310 if (info->rtfParam == 0)
311 fmt.dwEffects = CFE_AUTOBACKCOLOR;
312 else if (info->rtfParam != rtfNoParam)
314 RTFColor *c = RTFGetColor(info, info->rtfParam);
315 fmt.crTextColor = (c->rtfCBlue<<16)|(c->rtfCGreen<<8)|(c->rtfCRed);
317 break;
318 case rtfForeColor:
319 fmt.dwMask = CFM_COLOR;
320 fmt.dwEffects = 0;
321 if (info->rtfParam == 0)
322 fmt.dwEffects = CFE_AUTOCOLOR;
323 else if (info->rtfParam != rtfNoParam)
325 RTFColor *c = RTFGetColor(info, info->rtfParam);
326 fmt.crTextColor = (c->rtfCBlue<<16)|(c->rtfCGreen<<8)|(c->rtfCRed);
328 break;
329 case rtfFontNum:
330 if (info->rtfParam != rtfNoParam)
332 RTFFont *f = RTFGetFont(info, info->rtfParam);
333 if (f)
335 strncpy(fmt.szFaceName, f->rtfFName, sizeof(fmt.szFaceName)-1);
336 fmt.szFaceName[sizeof(fmt.szFaceName)-1] = '\0';
337 fmt.dwMask = CFM_FACE;
340 break;
341 case rtfFontSize:
342 fmt.dwMask = CFM_SIZE;
343 if (info->rtfParam != rtfNoParam)
344 fmt.yHeight = info->rtfParam*10;
345 break;
347 if (fmt.dwMask) {
348 RTFFlushOutputBuffer(info);
349 SendMessageW(info->hwndEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&fmt);
353 void ME_RTFParAttrHook(RTF_Info *info)
355 PARAFORMAT2 fmt;
356 fmt.cbSize = sizeof(fmt);
357 fmt.dwMask = 0;
359 switch(info->rtfMinor)
361 case rtfParDef: /* I'm not 100% sure what does it do, but I guess it restores default paragraph attributes */
362 fmt.dwMask = PFM_ALIGNMENT;
363 fmt.wAlignment = PFA_LEFT;
364 break;
365 case rtfQuadLeft:
366 case rtfQuadJust:
367 fmt.dwMask = PFM_ALIGNMENT;
368 fmt.wAlignment = PFA_LEFT;
369 break;
370 case rtfQuadRight:
371 fmt.dwMask = PFM_ALIGNMENT;
372 fmt.wAlignment = PFA_RIGHT;
373 break;
374 case rtfQuadCenter:
375 fmt.dwMask = PFM_ALIGNMENT;
376 fmt.wAlignment = PFA_CENTER;
377 break;
379 if (fmt.dwMask) {
380 RTFFlushOutputBuffer(info);
381 SendMessageW(info->hwndEdit, EM_SETPARAFORMAT, 0, (LPARAM)&fmt);
385 void ME_RTFReadHook(RTF_Info *info) {
386 switch(info->rtfClass)
388 case rtfControl:
389 switch(info->rtfMajor)
391 case rtfCharAttr:
392 ME_RTFCharAttrHook(info);
393 break;
394 case rtfParAttr:
395 ME_RTFParAttrHook(info);
396 break;
398 break;
402 static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stream)
404 RTF_Info parser;
405 ME_Style *style;
406 int from, to, to2, nUndoMode;
407 ME_UndoItem *pUI;
409 TRACE("%p %p\n", stream, editor->hWnd);
411 ME_GetSelection(editor, &from, &to);
412 if (format & SFF_SELECTION) {
413 style = ME_GetSelectionInsertStyle(editor);
415 ME_InternalDeleteText(editor, from, to-from);
417 else {
418 style = editor->pBuffer->pDefaultStyle;
419 ME_AddRefStyle(style);
420 SendMessageA(editor->hWnd, EM_SETSEL, 0, 0);
421 ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor));
422 from = to = 0;
423 ME_ClearTempStyle(editor);
426 nUndoMode = editor->nUndoMode;
427 editor->nUndoMode = umIgnore;
428 if (format & SF_RTF) {
429 /* setup the RTF parser */
430 memset(&parser, 0, sizeof parser);
431 RTFSetEditStream(&parser, stream);
432 parser.rtfFormat = format&(SF_TEXT|SF_RTF);
433 parser.hwndEdit = editor->hWnd;
434 WriterInit(&parser);
435 RTFInit(&parser);
436 RTFSetReadHook(&parser, ME_RTFReadHook);
437 BeginFile(&parser);
439 /* do the parsing */
440 RTFRead(&parser);
441 RTFFlushOutputBuffer(&parser);
443 else if (format & SF_TEXT)
444 ME_StreamInText(editor, format, stream, style);
445 else
446 ERR("EM_STREAMIN without SF_TEXT or SF_RTF\n");
447 ME_GetSelection(editor, &to, &to2);
448 /* put the cursor at the top */
449 if (!(format & SFF_SELECTION))
450 SendMessageA(editor->hWnd, EM_SETSEL, 0, 0);
451 else
453 /* FIXME where to put cursor now ? */
456 editor->nUndoMode = nUndoMode;
457 pUI = ME_AddUndoItem(editor, diUndoDeleteRun, NULL);
458 TRACE("from %d to %d\n", from, to);
459 if (pUI && from < to)
461 pUI->nStart = from;
462 pUI->nLen = to-from;
464 ME_CommitUndo(editor);
465 ME_ReleaseStyle(style);
467 return 0;
471 ME_DisplayItem *
472 ME_FindItemAtOffset(ME_TextEditor *editor, ME_DIType nItemType, int nOffset, int *nItemOffset)
474 ME_DisplayItem *item = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph);
476 while (item && item->member.para.next_para->member.para.nCharOfs <= nOffset)
477 item = ME_FindItemFwd(item, diParagraph);
479 if (!item)
480 return item;
482 nOffset -= item->member.para.nCharOfs;
483 if (nItemType == diParagraph) {
484 if (nItemOffset)
485 *nItemOffset = nOffset;
486 return item;
489 do {
490 item = ME_FindItemFwd(item, diRun);
491 } while (item && (item->member.run.nCharOfs + ME_StrLen(item->member.run.strText) <= nOffset));
492 if (item) {
493 nOffset -= item->member.run.nCharOfs;
494 if (nItemOffset)
495 *nItemOffset = nOffset;
497 return item;
501 ME_TextEditor *ME_MakeEditor(HWND hWnd) {
502 ME_TextEditor *ed = ALLOC_OBJ(ME_TextEditor);
503 HDC hDC;
504 int i;
505 ed->hWnd = hWnd;
506 ed->pBuffer = ME_MakeText();
507 hDC = GetDC(hWnd);
508 ME_MakeFirstParagraph(hDC, ed->pBuffer);
509 ReleaseDC(hWnd, hDC);
510 ed->bCaretShown = FALSE;
511 ed->nCursors = 3;
512 ed->pCursors = ALLOC_N_OBJ(ME_Cursor, ed->nCursors);
513 ed->pCursors[0].pRun = ME_FindItemFwd(ed->pBuffer->pFirst, diRun);
514 ed->pCursors[0].nOffset = 0;
515 ed->pCursors[1].pRun = ME_FindItemFwd(ed->pBuffer->pFirst, diRun);
516 ed->pCursors[1].nOffset = 0;
517 ed->nLastTotalLength = ed->nTotalLength = 0;
518 ed->nScrollPos = 0;
519 ed->nUDArrowX = -1;
520 ed->nSequence = 0;
521 ed->rgbBackColor = -1;
522 ed->bCaretAtEnd = FALSE;
523 ed->nEventMask = 0;
524 ed->nModifyStep = 0;
525 ed->pUndoStack = ed->pRedoStack = NULL;
526 ed->nUndoMode = umAddToUndo;
527 ed->nParagraphs = 1;
528 ed->nLastSelStart = ed->nLastSelEnd = 0;
529 for (i=0; i<HFONT_CACHE_SIZE; i++)
531 ed->pFontCache[i].nRefs = 0;
532 ed->pFontCache[i].nAge = 0;
533 ed->pFontCache[i].hFont = NULL;
535 ME_CheckCharOffsets(ed);
536 return ed;
539 typedef struct tagME_GlobalDestStruct
541 HGLOBAL hData;
542 int nLength;
543 } ME_GlobalDestStruct;
545 static DWORD CALLBACK ME_AppendToHGLOBAL(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
547 ME_GlobalDestStruct *pData = (ME_GlobalDestStruct *)dwCookie;
548 int nMaxSize;
549 BYTE *pDest;
551 nMaxSize = GlobalSize(pData->hData);
552 if (pData->nLength+cb+1 >= cb)
554 /* round up to 2^17 */
555 int nNewSize = (((nMaxSize+cb+1)|0x1FFFF)+1) & 0xFFFE0000;
556 pData->hData = GlobalReAlloc(pData->hData, nNewSize, 0);
558 pDest = (BYTE *)GlobalLock(pData->hData);
559 memcpy(pDest + pData->nLength, lpBuff, cb);
560 pData->nLength += cb;
561 pDest[pData->nLength] = '\0';
562 GlobalUnlock(pData->hData);
563 *pcb = cb;
565 return 0;
568 static DWORD CALLBACK ME_ReadFromHGLOBALUnicode(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
570 ME_GlobalDestStruct *pData = (ME_GlobalDestStruct *)dwCookie;
571 int i;
572 WORD *pSrc, *pDest;
574 cb = cb >> 1;
575 pDest = (WORD *)lpBuff;
576 pSrc = (WORD *)GlobalLock(pData->hData);
577 for (i = 0; i<cb && pSrc[pData->nLength+i]; i++) {
578 pDest[i] = pSrc[pData->nLength+i];
580 pData->nLength += i;
581 *pcb = 2*i;
582 GlobalUnlock(pData->hData);
583 return 0;
586 static DWORD CALLBACK ME_ReadFromHGLOBALRTF(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
588 ME_GlobalDestStruct *pData = (ME_GlobalDestStruct *)dwCookie;
589 int i;
590 BYTE *pSrc, *pDest;
592 pDest = lpBuff;
593 pSrc = (BYTE *)GlobalLock(pData->hData);
594 for (i = 0; i<cb && pSrc[pData->nLength+i]; i++) {
595 pDest[i] = pSrc[pData->nLength+i];
597 pData->nLength += i;
598 *pcb = i;
599 GlobalUnlock(pData->hData);
600 return 0;
603 void ME_DestroyEditor(ME_TextEditor *editor)
605 ME_DisplayItem *pFirst = editor->pBuffer->pFirst;
606 ME_DisplayItem *p = pFirst, *pNext = NULL;
607 int i;
609 ME_ClearTempStyle(editor);
610 ME_EmptyUndoStack(editor);
611 while(p) {
612 pNext = p->next;
613 ME_DestroyDisplayItem(p);
614 p = pNext;
616 ME_ReleaseStyle(editor->pBuffer->pDefaultStyle);
617 for (i=0; i<HFONT_CACHE_SIZE; i++)
619 if (editor->pFontCache[i].hFont)
620 DeleteObject(editor->pFontCache[i].hFont);
623 FREE_OBJ(editor);
626 #define UNSUPPORTED_MSG(e) \
627 case e: \
628 FIXME(#e ": stub\n"); \
629 return DefWindowProcW(hWnd, msg, wParam, lParam);
631 /******************************************************************
632 * RichEditANSIWndProc (RICHED20.10)
634 LRESULT WINAPI RichEditANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
635 HDC hDC;
636 PAINTSTRUCT ps;
637 SCROLLINFO si;
638 ME_TextEditor *editor = (ME_TextEditor *)GetWindowLongW(hWnd, 0);
639 TRACE("msg %d %08x %08lx\n", msg, wParam, lParam);
640 switch(msg) {
642 UNSUPPORTED_MSG(EM_AUTOURLDETECT)
643 UNSUPPORTED_MSG(EM_CANPASTE)
644 UNSUPPORTED_MSG(EM_CHARFROMPOS)
645 UNSUPPORTED_MSG(EM_DISPLAYBAND)
646 UNSUPPORTED_MSG(EM_EXLIMITTEXT)
647 UNSUPPORTED_MSG(EM_EXLINEFROMCHAR)
648 UNSUPPORTED_MSG(EM_FINDTEXT)
649 UNSUPPORTED_MSG(EM_FINDTEXTEX)
650 UNSUPPORTED_MSG(EM_FINDWORDBREAK)
651 UNSUPPORTED_MSG(EM_FMTLINES)
652 UNSUPPORTED_MSG(EM_FORMATRANGE)
653 UNSUPPORTED_MSG(EM_GETFIRSTVISIBLELINE)
654 UNSUPPORTED_MSG(EM_GETIMECOMPMODE)
655 /* UNSUPPORTED_MSG(EM_GETIMESTATUS) missing in Wine headers */
656 UNSUPPORTED_MSG(EM_GETLANGOPTIONS)
657 UNSUPPORTED_MSG(EM_GETLIMITTEXT)
658 UNSUPPORTED_MSG(EM_GETLINE)
659 UNSUPPORTED_MSG(EM_GETLINECOUNT)
660 /* UNSUPPORTED_MSG(EM_GETOLEINTERFACE) separate stub */
661 UNSUPPORTED_MSG(EM_GETOPTIONS)
662 UNSUPPORTED_MSG(EM_GETRECT)
663 UNSUPPORTED_MSG(EM_GETREDONAME)
664 UNSUPPORTED_MSG(EM_GETTEXTMODE)
665 UNSUPPORTED_MSG(EM_GETUNDONAME)
666 UNSUPPORTED_MSG(EM_GETWORDBREAKPROC)
667 UNSUPPORTED_MSG(EM_GETWORDBREAKPROCEX)
668 UNSUPPORTED_MSG(EM_HIDESELECTION)
669 UNSUPPORTED_MSG(EM_LIMITTEXT) /* also known as EM_SETLIMITTEXT */
670 UNSUPPORTED_MSG(EM_LINEFROMCHAR)
671 UNSUPPORTED_MSG(EM_LINEINDEX)
672 UNSUPPORTED_MSG(EM_LINELENGTH)
673 UNSUPPORTED_MSG(EM_LINESCROLL)
674 UNSUPPORTED_MSG(EM_PASTESPECIAL)
675 /* UNSUPPORTED_MSG(EM_POSFROMCHARS) missing in Wine headers */
676 UNSUPPORTED_MSG(EM_REQUESTRESIZE)
677 UNSUPPORTED_MSG(EM_SCROLL)
678 UNSUPPORTED_MSG(EM_SCROLLCARET)
679 UNSUPPORTED_MSG(EM_SELECTIONTYPE)
680 UNSUPPORTED_MSG(EM_SETLANGOPTIONS)
681 UNSUPPORTED_MSG(EM_SETOLECALLBACK)
682 UNSUPPORTED_MSG(EM_SETOPTIONS)
683 UNSUPPORTED_MSG(EM_SETRECT)
684 UNSUPPORTED_MSG(EM_SETRECTNP)
685 UNSUPPORTED_MSG(EM_SETTARGETDEVICE)
686 UNSUPPORTED_MSG(EM_SETTEXTMODE)
687 UNSUPPORTED_MSG(EM_SETUNDOLIMIT)
688 UNSUPPORTED_MSG(EM_SETWORDBREAKPROC)
689 UNSUPPORTED_MSG(EM_SETWORDBREAKPROCEX)
690 UNSUPPORTED_MSG(WM_SETFONT)
691 UNSUPPORTED_MSG(WM_STYLECHANGING)
692 UNSUPPORTED_MSG(WM_STYLECHANGED)
693 /* UNSUPPORTED_MSG(WM_UNICHAR) FIXME missing in Wine headers */
695 /* Messages specific to Richedit controls */
697 case EM_STREAMIN:
698 return ME_StreamIn(editor, wParam, (EDITSTREAM*)lParam);
699 case EM_STREAMOUT:
700 return ME_StreamOut(editor, wParam, (EDITSTREAM *)lParam);
701 case WM_GETDLGCODE:
703 UINT code = DLGC_WANTCHARS|DLGC_WANTARROWS;
704 if (GetWindowLongW(hWnd, GWL_STYLE)&ES_WANTRETURN)
705 code |= 0; /* FIXME what can we do here ? ask for messages and censor them ? */
706 return code;
708 case WM_NCCREATE:
710 CREATESTRUCTW *pcs = (CREATESTRUCTW *)lParam;
711 editor = ME_MakeEditor(hWnd);
712 SetWindowLongW(hWnd, 0, (long)editor);
713 pcs = 0; /* ignore */
714 return TRUE;
716 case EM_EMPTYUNDOBUFFER:
717 ME_EmptyUndoStack(editor);
718 return 0;
719 case EM_GETSEL:
721 ME_GetSelection(editor, (int *)wParam, (int *)lParam);
722 if (!((wParam|lParam) & 0xFFFF0000))
723 return (lParam<<16)|wParam;
724 return -1;
726 case EM_EXGETSEL:
728 CHARRANGE *pRange = (CHARRANGE *)lParam;
729 ME_GetSelection(editor, (int *)&pRange->cpMin, (int *)&pRange->cpMax);
730 return 0;
732 case EM_CANUNDO:
733 return editor->pUndoStack != NULL;
734 case EM_CANREDO:
735 return editor->pRedoStack != NULL;
736 case EM_UNDO:
737 ME_Undo(editor);
738 return 0;
739 case EM_REDO:
740 ME_Redo(editor);
741 return 0;
742 case EM_SETSEL:
744 ME_SetSelection(editor, wParam, lParam);
745 ME_Repaint(editor);
746 ME_SendSelChange(editor);
747 return 0;
749 case EM_EXSETSEL:
751 CHARRANGE *pRange = (CHARRANGE *)lParam;
752 ME_SetSelection(editor, pRange->cpMin, pRange->cpMax);
753 /* FIXME optimize */
754 ME_Repaint(editor);
755 ME_SendSelChange(editor);
756 return 0;
758 case EM_SETBKGNDCOLOR:
760 LRESULT lColor = ME_GetBackColor(editor);
761 if (wParam)
762 editor->rgbBackColor = -1;
763 else
764 editor->rgbBackColor = lParam;
765 InvalidateRect(hWnd, NULL, TRUE);
766 UpdateWindow(hWnd);
767 return lColor;
769 case EM_GETMODIFY:
770 return editor->nModifyStep == 0 ? 0 : 1;
771 case EM_SETMODIFY:
773 if (wParam)
774 editor->nModifyStep = 0x80000000;
775 else
776 editor->nModifyStep = 0;
778 return 0;
780 case EM_SETREADONLY:
782 long nStyle = GetWindowLongW(hWnd, GWL_STYLE);
783 if (wParam)
784 nStyle |= ES_READONLY;
785 else
786 nStyle &= ~ES_READONLY;
787 SetWindowLongW(hWnd, GWL_STYLE, nStyle);
788 ME_Repaint(editor);
789 return 0;
791 case EM_SETEVENTMASK:
792 editor->nEventMask = lParam;
793 return 0;
794 case EM_GETEVENTMASK:
795 return editor->nEventMask;
796 case EM_SETCHARFORMAT:
798 CHARFORMAT2W buf, *p;
799 p = ME_ToCF2W(&buf, (CHARFORMAT2W *)lParam);
800 if (!wParam)
801 ME_SetDefaultCharFormat(editor, p);
802 else if (wParam == (SCF_WORD | SCF_SELECTION))
803 FIXME("word selection not supported\n");
804 else if (wParam == SCF_ALL)
805 ME_SetCharFormat(editor, 0, ME_GetTextLength(editor), p);
806 else
807 ME_SetSelectionCharFormat(editor, p);
808 ME_CommitUndo(editor);
809 ME_UpdateRepaint(editor);
810 return 0;
812 case EM_GETCHARFORMAT:
814 CHARFORMAT2W tmp;
815 tmp.cbSize = sizeof(tmp);
816 if (!wParam)
817 ME_GetDefaultCharFormat(editor, &tmp);
818 else
819 ME_GetSelectionCharFormat(editor, &tmp);
820 ME_CopyToCFAny((CHARFORMAT2W *)lParam, &tmp);
821 return 0;
823 case EM_SETPARAFORMAT:
824 ME_SetSelectionParaFormat(editor, (PARAFORMAT2 *)lParam);
825 ME_CommitUndo(editor);
826 return 0;
827 case EM_GETPARAFORMAT:
828 ME_GetSelectionParaFormat(editor, (PARAFORMAT2 *)lParam);
829 return 0;
830 case WM_CLEAR:
832 int from, to;
833 ME_GetSelection(editor, &from, &to);
834 ME_InternalDeleteText(editor, from, to-from);
835 ME_CommitUndo(editor);
836 ME_UpdateRepaint(editor);
837 return 0;
839 case EM_REPLACESEL:
841 int from, to;
842 ME_Style *style;
843 LPWSTR wszText = ME_ToUnicode(hWnd, (void *)lParam);
844 size_t len = lstrlenW(wszText);
845 TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText));
847 ME_GetSelection(editor, &from, &to);
848 style = ME_GetSelectionInsertStyle(editor);
849 ME_InternalDeleteText(editor, from, to-from);
850 ME_InsertTextFromCursor(editor, 0, wszText, len, style);
851 ME_ReleaseStyle(style);
852 ME_EndToUnicode(hWnd, wszText);
853 /* drop temporary style if line end */
854 /* FIXME question: does abc\n mean: put abc, clear temp style, put \n? (would require a change) */
855 if (len>0 && wszText[len-1] == '\n')
856 ME_ClearTempStyle(editor);
858 ME_CommitUndo(editor);
859 if (!wParam)
860 ME_EmptyUndoStack(editor);
861 ME_UpdateRepaint(editor);
862 return 0;
864 case WM_SETTEXT:
866 LPWSTR wszText = ME_ToUnicode(hWnd, (void *)lParam);
867 TRACE("WM_SETTEXT - %s\n", (char *)(wszText)); /* debugstr_w() */
868 ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor));
869 /* uses default style! */
870 ME_InsertTextFromCursor(editor, 0, wszText, -1, editor->pBuffer->pDefaultStyle);
871 ME_EndToUnicode(hWnd, wszText);
872 ME_CommitUndo(editor);
873 ME_EmptyUndoStack(editor);
874 ME_UpdateRepaint(editor);
875 return 0;
877 case WM_PASTE:
879 DWORD dwFormat = 0;
880 EDITSTREAM es;
881 ME_GlobalDestStruct gds;
882 UINT nRTFFormat = RegisterClipboardFormatA("Rich Text Format");
883 UINT cf = 0;
885 if (!OpenClipboard(hWnd))
886 return 0;
887 if (IsClipboardFormatAvailable(nRTFFormat))
888 cf = nRTFFormat, dwFormat = SF_RTF;
889 else if (IsClipboardFormatAvailable(CF_UNICODETEXT))
890 cf = CF_UNICODETEXT, dwFormat = SF_TEXT|SF_UNICODE;
891 else
892 return 0;
894 gds.hData = GetClipboardData(cf);
895 gds.nLength = 0;
896 es.dwCookie = (DWORD)&gds;
897 es.pfnCallback = dwFormat == SF_RTF ? ME_ReadFromHGLOBALRTF : ME_ReadFromHGLOBALUnicode;
898 SendMessageW(hWnd, EM_STREAMIN, dwFormat|SFF_SELECTION, (LPARAM)&es);
900 CloseClipboard();
901 return 0;
903 case WM_CUT:
904 case WM_COPY:
906 int from, to, pars;
907 WCHAR *data;
908 HANDLE hData;
909 EDITSTREAM es;
910 ME_GlobalDestStruct gds;
912 if (!OpenClipboard(hWnd))
913 return 0;
915 EmptyClipboard();
916 ME_GetSelection(editor, &from, &to);
917 pars = ME_CountParagraphsBetween(editor, from, to);
918 hData = GlobalAlloc(GMEM_MOVEABLE, sizeof(WCHAR)*(to-from+pars+1));
919 data = (WCHAR *)GlobalLock(hData);
920 ME_GetTextW(editor, data, from, to-from, TRUE);
921 GlobalUnlock(hData);
923 gds.hData = GlobalAlloc(GMEM_MOVEABLE, 0);
924 gds.nLength = 0;
925 es.dwCookie = (DWORD)&gds;
926 es.pfnCallback = ME_AppendToHGLOBAL;
927 SendMessageW(hWnd, EM_STREAMOUT, SFF_SELECTION|SF_RTF, (LPARAM)&es);
928 GlobalReAlloc(gds.hData, gds.nLength+1, 0);
930 SetClipboardData(CF_UNICODETEXT, hData);
931 SetClipboardData(RegisterClipboardFormatA("Rich Text Format"), gds.hData);
933 CloseClipboard();
934 if (msg == WM_CUT)
936 ME_InternalDeleteText(editor, from, to-from);
937 ME_CommitUndo(editor);
938 ME_UpdateRepaint(editor);
940 return 0;
942 case WM_GETTEXTLENGTH:
943 return ME_GetTextLength(editor);
944 case WM_GETTEXT:
946 TEXTRANGEW tr; /* W and A differ only by rng->lpstrText */
947 tr.chrg.cpMin = 0;
948 tr.chrg.cpMax = wParam-1;
949 tr.lpstrText = (WCHAR *)lParam;
950 return RichEditANSIWndProc(hWnd, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
952 case EM_GETSELTEXT:
954 int from, to;
955 TEXTRANGEW tr; /* W and A differ only by rng->lpstrText */
956 ME_GetSelection(editor, &from, &to);
957 tr.chrg.cpMin = from;
958 tr.chrg.cpMax = to;
959 tr.lpstrText = (WCHAR *)lParam;
960 return RichEditANSIWndProc(hWnd, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
962 case EM_GETTEXTRANGE:
964 TEXTRANGEW *rng = (TEXTRANGEW *)lParam;
965 if (IsWindowUnicode(hWnd))
966 return ME_GetTextW(editor, rng->lpstrText, rng->chrg.cpMin, rng->chrg.cpMax-rng->chrg.cpMin, FALSE);
967 else
969 int nLen = rng->chrg.cpMax-rng->chrg.cpMin;
970 WCHAR *p = ALLOC_N_OBJ(WCHAR, nLen+1);
971 int nChars = ME_GetTextW(editor, p, rng->chrg.cpMin, nLen, FALSE);
972 /* FIXME this is a potential security hole (buffer overrun)
973 if you know more about wchar->mbyte conversion please explain
975 WideCharToMultiByte(CP_ACP, 0, p, nChars+1, (char *)rng->lpstrText, nLen+1, NULL, NULL);
976 FREE_OBJ(p);
977 return nChars;
979 return ME_GetTextW(editor, rng->lpstrText, rng->chrg.cpMin, rng->chrg.cpMax-rng->chrg.cpMin, FALSE);
981 case WM_CREATE:
982 ME_CommitUndo(editor);
983 ME_WrapMarkedParagraphs(editor);
984 ME_MoveCaret(editor);
985 return 0;
986 case WM_DESTROY:
987 ME_DestroyEditor(editor);
988 SetWindowLongW(hWnd, 0, 0);
989 return 0;
990 case WM_LBUTTONDOWN:
991 SetFocus(hWnd);
992 ME_LButtonDown(editor, (short)LOWORD(lParam), (short)HIWORD(lParam));
993 SetCapture(hWnd);
994 break;
995 case WM_MOUSEMOVE:
996 if (GetCapture() == hWnd)
997 ME_MouseMove(editor, (short)LOWORD(lParam), (short)HIWORD(lParam));
998 break;
999 case WM_LBUTTONUP:
1000 if (GetCapture() == hWnd)
1001 ReleaseCapture();
1002 break;
1003 case WM_PAINT:
1004 hDC = BeginPaint(hWnd, &ps);
1005 ME_PaintContent(editor, hDC, FALSE, &ps.rcPaint);
1006 EndPaint(hWnd, &ps);
1007 break;
1008 case WM_SETFOCUS:
1009 ME_ShowCaret(editor);
1010 ME_SendOldNotify(editor, EN_SETFOCUS);
1011 return 0;
1012 case WM_KILLFOCUS:
1013 ME_HideCaret(editor);
1014 ME_SendOldNotify(editor, EN_KILLFOCUS);
1015 return 0;
1016 case WM_ERASEBKGND:
1018 HDC hDC = (HDC)wParam;
1019 RECT rc;
1020 COLORREF rgbBG = ME_GetBackColor(editor);
1021 if (GetUpdateRect(hWnd,&rc,TRUE))
1023 HBRUSH hbr = CreateSolidBrush(rgbBG);
1024 FillRect(hDC, &rc, hbr);
1025 DeleteObject(hbr);
1027 return 1;
1029 case WM_COMMAND:
1030 TRACE("editor wnd command = %d\n", LOWORD(wParam));
1031 return 0;
1032 case WM_KEYDOWN:
1033 if (ME_ArrowKey(editor, LOWORD(wParam), GetKeyState(VK_CONTROL)<0)) {
1034 ME_CommitUndo(editor);
1035 ME_EnsureVisible(editor, editor->pCursors[0].pRun);
1036 HideCaret(hWnd);
1037 ME_MoveCaret(editor);
1038 ShowCaret(hWnd);
1039 return 0;
1041 if (GetKeyState(VK_CONTROL)<0)
1043 if (LOWORD(wParam)=='W')
1045 CHARFORMAT2W chf;
1046 char buf[2048];
1047 ME_GetSelectionCharFormat(editor, &chf);
1048 ME_DumpStyleToBuf(&chf, buf);
1049 MessageBoxA(NULL, buf, "Style dump", MB_OK);
1051 if (LOWORD(wParam)=='Q')
1053 ME_CheckCharOffsets(editor);
1056 goto do_default;
1057 case WM_CHAR:
1059 WCHAR wstr;
1060 if (GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_READONLY) {
1061 MessageBeep(MB_ICONERROR);
1062 return 0; /* FIXME really 0 ? */
1064 wstr = LOWORD(wParam);
1065 if (((unsigned)wstr)>=' ' || wstr=='\r') {
1066 /* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */
1067 ME_Style *style = ME_GetInsertStyle(editor, 0);
1068 ME_SaveTempStyle(editor);
1069 ME_InsertTextFromCursor(editor, 0, &wstr, 1, style);
1070 ME_ReleaseStyle(style);
1071 ME_CommitUndo(editor);
1072 ME_UpdateRepaint(editor);
1074 return 0;
1076 case WM_VSCROLL:
1078 si.cbSize = sizeof(SCROLLINFO);
1079 si.fMask = SIF_PAGE|SIF_POS|SIF_RANGE|SIF_TRACKPOS;
1080 GetScrollInfo(hWnd, SB_VERT, &si);
1081 switch(LOWORD(wParam)) {
1082 case SB_THUMBTRACK:
1083 SetScrollPos(hWnd, SB_VERT, si.nTrackPos, FALSE);
1084 ScrollWindow(hWnd, 0, si.nPos-si.nTrackPos, NULL, NULL);
1085 /* InvalidateRect(hWnd, NULL, TRUE); */
1086 UpdateWindow(hWnd);
1087 break;
1089 break;
1091 case WM_SIZE:
1093 ME_MarkAllForWrapping(editor);
1094 ME_Repaint(editor);
1095 return DefWindowProcW(hWnd, msg, wParam, lParam);
1097 case EM_GETOLEINTERFACE:
1099 LPVOID *ppvObj = (LPVOID*) lParam;
1100 FIXME("EM_GETOLEINTERFACE %p: stub\n", ppvObj);
1101 return CreateIRichEditOle(ppvObj);
1103 default:
1104 do_default:
1105 return DefWindowProcW(hWnd, msg, wParam, lParam);
1107 return 0L;
1110 /******************************************************************
1111 * RichEdit10ANSIWndProc (RICHED20.9)
1113 LRESULT WINAPI RichEdit10ANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1115 /* FIXME: this is NOT the same as 2.0 version */
1116 return RichEditANSIWndProc(hWnd, msg, wParam, lParam);
1119 void ME_SendOldNotify(ME_TextEditor *editor, int nCode)
1121 HWND hWnd = editor->hWnd;
1122 SendMessageA(GetParent(hWnd), WM_COMMAND, (nCode<<16)|GetWindowLongW(hWnd, GWLP_ID), (LPARAM)hWnd);
1125 int ME_CountParagraphsBetween(ME_TextEditor *editor, int from, int to)
1127 ME_DisplayItem *item = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph);
1128 int i = 0;
1130 while(item && item->member.para.next_para->member.para.nCharOfs <= from)
1131 item = item->member.para.next_para;
1132 if (!item)
1133 return 0;
1134 while(item && item->member.para.next_para->member.para.nCharOfs <= to) {
1135 item = item->member.para.next_para;
1136 i++;
1138 return i;
1142 int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int nStart, int nChars, int bCRLF)
1144 ME_DisplayItem *item = ME_FindItemAtOffset(editor, diRun, nStart, &nStart);
1145 int nWritten = 0;
1147 if (!item) {
1148 *buffer = L'\0';
1149 return 0;
1151 assert(item);
1153 if (nStart)
1155 int nLen = ME_StrLen(item->member.run.strText) - nStart;
1156 if (nLen > nChars)
1157 nLen = nChars;
1158 CopyMemory(buffer, item->member.run.strText->szData + nStart, sizeof(WCHAR)*nLen);
1159 nChars -= nLen;
1160 nWritten += nLen;
1161 if (!nChars)
1162 return nWritten;
1163 buffer += nLen;
1164 nStart = 0;
1165 item = ME_FindItemFwd(item, diRun);
1168 while(nChars && item)
1170 int nLen = ME_StrLen(item->member.run.strText);
1171 if (nLen > nChars)
1172 nLen = nChars;
1174 if (item->member.run.nFlags & MERF_ENDPARA)
1176 if (bCRLF) {
1177 *buffer++ = '\r';
1178 nWritten++;
1180 *buffer = '\n';
1181 assert(nLen == 1);
1183 else
1184 CopyMemory(buffer, item->member.run.strText->szData, sizeof(WCHAR)*nLen);
1185 nChars -= nLen;
1186 nWritten += nLen;
1187 buffer += nLen;
1189 if (!nChars)
1191 *buffer = L'\0';
1192 return nWritten;
1194 item = ME_FindItemFwd(item, diRun);
1196 *buffer = L'\0';
1197 return nWritten;
1200 static WCHAR wszClassName[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '2', '0', 'W', 0};
1201 static WCHAR wszClassName50[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '5', '0', 'W', 0};
1203 void ME_RegisterEditorClass(HINSTANCE hInstance)
1205 BOOL bResult;
1206 WNDCLASSW wcW;
1207 WNDCLASSA wcA;
1209 wcW.style = CS_HREDRAW | CS_VREDRAW;
1210 wcW.lpfnWndProc = RichEditANSIWndProc;
1211 wcW.cbClsExtra = 0;
1212 wcW.cbWndExtra = 4;
1213 wcW.hInstance = NULL; /* hInstance would register DLL-local class */
1214 wcW.hIcon = NULL;
1215 wcW.hCursor = LoadCursorW(NULL, MAKEINTRESOURCEW(IDC_IBEAM));
1216 wcW.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
1217 wcW.lpszMenuName = NULL;
1218 wcW.lpszClassName = wszClassName;
1219 bResult = RegisterClassW(&wcW);
1220 assert(bResult);
1221 wcW.lpszClassName = wszClassName50;
1222 bResult = RegisterClassW(&wcW);
1223 assert(bResult);
1225 wcA.style = CS_HREDRAW | CS_VREDRAW;
1226 wcA.lpfnWndProc = RichEditANSIWndProc;
1227 wcA.cbClsExtra = 0;
1228 wcA.cbWndExtra = 4;
1229 wcA.hInstance = NULL; /* hInstance would register DLL-local class */
1230 wcA.hIcon = NULL;
1231 wcA.hCursor = LoadCursorW(NULL, MAKEINTRESOURCEW(IDC_IBEAM));
1232 wcA.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
1233 wcA.lpszMenuName = NULL;
1234 wcA.lpszClassName = "RichEdit20A";
1235 bResult = RegisterClassA(&wcA);
1236 assert(bResult);
1237 wcA.lpszClassName = "RichEdit50A";
1238 bResult = RegisterClassA(&wcA);
1239 assert(bResult);
1242 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
1244 TRACE("\n");
1245 switch (fdwReason)
1247 case DLL_PROCESS_ATTACH:
1248 DisableThreadLibraryCalls(hinstDLL);
1249 me_heap = HeapCreate (0, 0x10000, 0);
1250 ME_RegisterEditorClass(hinstDLL);
1251 break;
1253 case DLL_PROCESS_DETACH:
1254 UnregisterClassW(wszClassName, 0);
1255 UnregisterClassW(wszClassName50, 0);
1256 UnregisterClassA("RichEdit20A", 0);
1257 UnregisterClassA("RichEdit50A", 0);
1258 HeapDestroy (me_heap);
1259 me_heap = NULL;
1260 break;
1262 return TRUE;
1265 /******************************************************************
1266 * CreateTextServices (RICHED20.4)
1268 * FIXME should be ITextHost instead of void*
1270 HRESULT WINAPI CreateTextServices(IUnknown *punkOuter, void *pITextHost,
1271 IUnknown **ppUnk)
1273 FIXME("stub\n");
1274 /* FIXME should support aggregation */
1275 if (punkOuter)
1276 return CLASS_E_NOAGGREGATION;
1278 return E_FAIL; /* E_NOTIMPL isn't allowed by MSDN */
1281 /******************************************************************
1282 * REExtendedRegisterClass (RICHED20.8)
1284 * FIXME undocumented
1286 void WINAPI REExtendedRegisterClass(void)
1288 FIXME("stub\n");